@onekeyfe/react-native-jpush 6.7.0-alpha.445 → 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.
- package/android/fcm/src/test/java/com/onekey/jpush/fcm/FcmAdapterTest.java +212 -0
- package/android/src/main/cpp/cpp-adapter.cpp +41 -1
- package/android/src/main/java/cn/jiguang/core/JCoreCrypto.java +6 -9
- package/android/src/main/java/cn/jiguang/core/JCoreStorage.java +14 -2
- package/android/src/main/java/cn/jiguang/core/JCoreTcpEngine.java +476 -348
- package/android/src/main/java/cn/jiguang/core/JCoreWireCodec.java +1 -0
- package/android/src/main/java/cn/jiguang/plugins/core/JCoreModule.java +13 -2
- package/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java +38 -2
- package/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java +46 -15
- package/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java +0 -3
- package/android/src/main/java/cn/jpush/android/api/JPushInterface.java +0 -1
- package/android/src/main/java/cn/jpush/android/local/ActionHelper.java +223 -272
- package/android/src/main/java/cn/jpush/android/service/JNotifyActivity.java +1 -1
- package/android/src/main/java/com/margelo/nitro/reactnativejpush/ReactNativeJpush.kt +51 -16
- package/android/src/test/java/com/margelo/nitro/reactnativejpush/ReactNativeJpushProtocolTest.java +76 -32
- package/ios/bridge/RCTJPushModule.m +215 -150
- package/ios/jcore/JCOREConfiguration.h +5 -0
- package/ios/jcore/JCOREConfiguration.m +44 -4
- package/ios/jcore/JCORECrypto.m +10 -12
- package/ios/jcore/JCORETcpSession.m +197 -45
- package/ios/jcore/JCOREWireProtocol.m +20 -7
- package/ios/jpush/JPUSHNotificationManager.m +7 -1
- package/ios/jpush/JPUSHService.m +7 -9
- package/package.json +1 -1
package/ios/jcore/JCORECrypto.m
CHANGED
|
@@ -562,20 +562,18 @@ static NSData *JCORESm4StripPkcs7Padding(NSData *decrypted) {
|
|
|
562
562
|
if (inflateInit2(&stream, 15 + 32) != Z_OK) {
|
|
563
563
|
return nil;
|
|
564
564
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
}
|
|
575
|
-
if (inflateEnd(&stream) != Z_OK || status != Z_STREAM_END) {
|
|
565
|
+
// One extra byte distinguishes an exact-limit result from an oversized result.
|
|
566
|
+
const NSUInteger decodedLimit = 65536;
|
|
567
|
+
NSMutableData *decompressed = [NSMutableData dataWithLength:decodedLimit + 1];
|
|
568
|
+
stream.next_out = decompressed.mutableBytes;
|
|
569
|
+
stream.avail_out = (uInt)decompressed.length;
|
|
570
|
+
int status = inflate(&stream, Z_FINISH);
|
|
571
|
+
NSUInteger decodedLength = stream.total_out;
|
|
572
|
+
int endStatus = inflateEnd(&stream);
|
|
573
|
+
if (endStatus != Z_OK || status != Z_STREAM_END || decodedLength > decodedLimit) {
|
|
576
574
|
return nil;
|
|
577
575
|
}
|
|
578
|
-
decompressed.length =
|
|
576
|
+
decompressed.length = decodedLength;
|
|
579
577
|
return decompressed;
|
|
580
578
|
}
|
|
581
579
|
|
|
@@ -23,6 +23,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
23
23
|
@interface JCOREQueuedWireRequest : NSObject
|
|
24
24
|
@property (nonatomic, assign) uint8_t command;
|
|
25
25
|
@property (nonatomic, assign) uint8_t version;
|
|
26
|
+
@property (nonatomic, assign) NSUInteger policyGeneration;
|
|
26
27
|
@property (nonatomic, strong) NSData *bodyData;
|
|
27
28
|
@property (nonatomic, copy, nullable) JCORETcpResponseHandler completion;
|
|
28
29
|
@end
|
|
@@ -74,6 +75,13 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
74
75
|
BOOL _connected;
|
|
75
76
|
BOOL _loggedIn;
|
|
76
77
|
BOOL _userDisconnected;
|
|
78
|
+
BOOL _initialized;
|
|
79
|
+
NSUInteger _policyGeneration;
|
|
80
|
+
NSUInteger _attemptGeneration;
|
|
81
|
+
NSString *_inFlightDeviceTokenHex;
|
|
82
|
+
NSString *_inFlightVoipTokenHex;
|
|
83
|
+
NSUInteger _deviceTokenReportGeneration;
|
|
84
|
+
NSUInteger _voipTokenReportGeneration;
|
|
77
85
|
NSString *_lastReportedDeviceTokenHex;
|
|
78
86
|
NSString *_lastReportedVoipTokenHex;
|
|
79
87
|
}
|
|
@@ -97,11 +105,82 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
97
105
|
_receiveBuffer = [NSMutableData data];
|
|
98
106
|
_inFlightRequests = [NSMutableDictionary dictionary];
|
|
99
107
|
_queuedRequests = [NSMutableArray array];
|
|
108
|
+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(policyDidChange:) name:JCOREPolicyDidChangeNotification object:nil];
|
|
100
109
|
[self setupNetworkAndLifecycleMonitors];
|
|
101
110
|
}
|
|
102
111
|
return self;
|
|
103
112
|
}
|
|
104
113
|
|
|
114
|
+
- (BOOL)ownsCurrentPolicy {
|
|
115
|
+
return [[JCOREConfiguration shared] allowsPolicyGeneration:_policyGeneration];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
- (void)failQueuedRequestsLocked {
|
|
119
|
+
NSArray<JCOREQueuedWireRequest *> *snapshot = [_queuedRequests copy];
|
|
120
|
+
[_queuedRequests removeAllObjects];
|
|
121
|
+
NSError *error = [NSError errorWithDomain:@"cn.jiguang.jpush" code:6002
|
|
122
|
+
userInfo:@{NSLocalizedDescriptionKey: @"Request cancelled"}];
|
|
123
|
+
for (JCOREQueuedWireRequest *request in snapshot) {
|
|
124
|
+
if (request.completion) { request.completion(nil, error); }
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
- (void)discardQueuedRequestsOutsideGenerationLocked:(NSUInteger)generation {
|
|
129
|
+
NSArray<JCOREQueuedWireRequest *> *snapshot = [_queuedRequests copy];
|
|
130
|
+
[_queuedRequests removeAllObjects];
|
|
131
|
+
for (JCOREQueuedWireRequest *request in snapshot) {
|
|
132
|
+
if (request.policyGeneration == generation) { [_queuedRequests addObject:request]; }
|
|
133
|
+
else if (request.completion) {
|
|
134
|
+
request.completion(nil, [NSError errorWithDomain:@"cn.jiguang.jpush" code:6002 userInfo:nil]);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
- (void)policyDidChange:(NSNotification *)notification {
|
|
140
|
+
NSUInteger generation = [notification.userInfo[@"generation"] unsignedIntegerValue];
|
|
141
|
+
dispatch_async(_sessionQueue, ^{
|
|
142
|
+
JCOREConfiguration *config = [JCOREConfiguration shared];
|
|
143
|
+
if (generation != config.policyGeneration ||
|
|
144
|
+
(config.policyAllowsPush && self->_policyGeneration == generation)) { return; }
|
|
145
|
+
self->_attemptGeneration++;
|
|
146
|
+
[self cancelReconnectTimerLocked];
|
|
147
|
+
if (config.policyAllowsPush) {
|
|
148
|
+
[self discardQueuedRequestsOutsideGenerationLocked:generation];
|
|
149
|
+
} else {
|
|
150
|
+
[self failQueuedRequestsLocked];
|
|
151
|
+
}
|
|
152
|
+
// Stop control is the final write on the old connection; all content is already gated.
|
|
153
|
+
if (generation == config.policyGeneration && config.collectionAuthorized && config.pushStopped &&
|
|
154
|
+
self->_connected && self->_loggedIn && self->_connection != nil) {
|
|
155
|
+
nw_connection_t connection = self->_connection;
|
|
156
|
+
NSData *packet = [JCOREWireProtocol encodeFrameWithCommand:JCOREWireCommandPushCtrl version:1
|
|
157
|
+
requestId:[config nextRequestId] sessionId:self->_sessionId uid:config.uid
|
|
158
|
+
bodyData:[JCOREWireProtocol buildPushControlPayloadWithStopped:YES]];
|
|
159
|
+
if (generation != config.policyGeneration || !config.collectionAuthorized || !config.pushStopped) {
|
|
160
|
+
self->_connecting = NO;
|
|
161
|
+
[self tearDownConnectionLocked];
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
dispatch_data_t data = dispatch_data_create(packet.bytes, packet.length, self->_sessionQueue, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
|
|
165
|
+
nw_connection_send(connection, data, NW_CONNECTION_DEFAULT_MESSAGE_CONTEXT, true, ^(nw_error_t error) {
|
|
166
|
+
(void)error;
|
|
167
|
+
if (self->_connection == connection) {
|
|
168
|
+
self->_connecting = NO;
|
|
169
|
+
[self tearDownConnectionLocked];
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
[self stopHeartbeatLocked];
|
|
173
|
+
[self failAllInFlightRequestsLockedWithError:[NSError errorWithDomain:@"cn.jiguang.jpush" code:6002 userInfo:nil]];
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
self->_connecting = NO;
|
|
177
|
+
[self tearDownConnectionLocked];
|
|
178
|
+
if (generation == config.policyGeneration && config.policyAllowsPush && self->_initialized && !self->_userDisconnected) {
|
|
179
|
+
[self startLockedForceReconnect:NO];
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
105
184
|
- (void)setupNetworkAndLifecycleMonitors {
|
|
106
185
|
nw_path_monitor_t monitor = nw_path_monitor_create();
|
|
107
186
|
if (monitor != nil) {
|
|
@@ -182,13 +261,24 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
182
261
|
}
|
|
183
262
|
|
|
184
263
|
- (void)postNotificationOnMain:(NSString *)name userInfo:(nullable NSDictionary *)userInfo {
|
|
264
|
+
NSUInteger generation = [name isEqualToString:kJPFNetworkDidReceiveMessageNotification]
|
|
265
|
+
? _policyGeneration : [JCOREConfiguration shared].policyGeneration;
|
|
185
266
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
186
|
-
[
|
|
267
|
+
if ([name isEqualToString:kJPFNetworkDidReceiveMessageNotification] &&
|
|
268
|
+
![[JCOREConfiguration shared] allowsPolicyGeneration:generation]) { return; }
|
|
269
|
+
NSDictionary *notificationInfo = userInfo;
|
|
270
|
+
if ([name isEqualToString:kJPFNetworkDidReceiveMessageNotification]) {
|
|
271
|
+
NSMutableDictionary *info = [NSMutableDictionary dictionaryWithDictionary:userInfo ?: @{}];
|
|
272
|
+
info[@"_j_InternalPolicyGeneration"] = @(generation);
|
|
273
|
+
notificationInfo = info;
|
|
274
|
+
}
|
|
275
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:name object:userInfo userInfo:notificationInfo];
|
|
187
276
|
});
|
|
188
277
|
}
|
|
189
278
|
|
|
190
279
|
- (void)startIfNeeded {
|
|
191
280
|
dispatch_async(_sessionQueue, ^{
|
|
281
|
+
self->_initialized = YES;
|
|
192
282
|
self->_userDisconnected = NO;
|
|
193
283
|
[self startLockedForceReconnect:NO];
|
|
194
284
|
});
|
|
@@ -196,6 +286,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
196
286
|
|
|
197
287
|
- (void)reconnect {
|
|
198
288
|
dispatch_async(_sessionQueue, ^{
|
|
289
|
+
self->_initialized = YES;
|
|
199
290
|
self->_userDisconnected = NO;
|
|
200
291
|
self->_reconnectAttempt = 0;
|
|
201
292
|
[self startLockedForceReconnect:YES];
|
|
@@ -204,7 +295,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
204
295
|
|
|
205
296
|
- (void)startLockedForceReconnect:(BOOL)forceReconnect {
|
|
206
297
|
JCOREConfiguration *config = [JCOREConfiguration shared];
|
|
207
|
-
if (config.appKey.length == 0 || config.
|
|
298
|
+
if (!_initialized || config.appKey.length == 0 || !config.policyAllowsPush) {
|
|
208
299
|
return;
|
|
209
300
|
}
|
|
210
301
|
[self cancelReconnectTimerLocked];
|
|
@@ -216,13 +307,19 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
216
307
|
return;
|
|
217
308
|
}
|
|
218
309
|
_connecting = YES;
|
|
310
|
+
_policyGeneration = config.policyGeneration;
|
|
311
|
+
[self discardQueuedRequestsOutsideGenerationLocked:_policyGeneration];
|
|
312
|
+
NSUInteger attemptGeneration = ++_attemptGeneration;
|
|
313
|
+
_inFlightDeviceTokenHex = nil;
|
|
314
|
+
_inFlightVoipTokenHex = nil;
|
|
219
315
|
_lastReportedDeviceTokenHex = nil;
|
|
220
316
|
_lastReportedVoipTokenHex = nil;
|
|
221
317
|
[self postNotificationOnMain:kJPFNetworkIsConnectingNotification userInfo:nil];
|
|
222
318
|
|
|
223
319
|
[[JCORESisResolver shared] resolveEndpointsWithCompletion:^(NSArray<JCORESisEndpoint *> *endpoints) {
|
|
224
320
|
dispatch_async(self->_sessionQueue, ^{
|
|
225
|
-
if (self->
|
|
321
|
+
if (attemptGeneration != self->_attemptGeneration || ![self ownsCurrentPolicy]) { return; }
|
|
322
|
+
if (self->_userDisconnected) {
|
|
226
323
|
self->_connecting = NO;
|
|
227
324
|
return;
|
|
228
325
|
}
|
|
@@ -293,7 +390,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
293
390
|
nw_connection_set_state_changed_handler(connection, ^(nw_connection_state_t state, nw_error_t error) {
|
|
294
391
|
(void)error;
|
|
295
392
|
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
296
|
-
if (!strongSelf || strongSelf->_connection != connection) {
|
|
393
|
+
if (!strongSelf || strongSelf->_connection != connection || ![strongSelf ownsCurrentPolicy]) {
|
|
297
394
|
return;
|
|
298
395
|
}
|
|
299
396
|
if (state == nw_connection_state_ready) {
|
|
@@ -353,7 +450,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
353
450
|
__weak typeof(self) weakSelf = self;
|
|
354
451
|
dispatch_source_set_event_handler(timer, ^{
|
|
355
452
|
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
356
|
-
if (!strongSelf || strongSelf->_connection != connection || strongSelf->_connected) {
|
|
453
|
+
if (!strongSelf || strongSelf->_connection != connection || strongSelf->_connected || ![strongSelf ownsCurrentPolicy]) {
|
|
357
454
|
return;
|
|
358
455
|
}
|
|
359
456
|
[strongSelf advanceToNextCandidateAfterFailureOfEndpoint:endpoint];
|
|
@@ -371,7 +468,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
371
468
|
|
|
372
469
|
- (void)scheduleReconnectLocked {
|
|
373
470
|
[self cancelReconnectTimerLocked];
|
|
374
|
-
if (_userDisconnected || [JCOREConfiguration shared].
|
|
471
|
+
if (_userDisconnected || ![JCOREConfiguration shared].policyAllowsPush || [JCOREConfiguration shared].appKey.length == 0) {
|
|
375
472
|
return;
|
|
376
473
|
}
|
|
377
474
|
NSTimeInterval base = [JCOREConfiguration shared].reconnectBaseInterval;
|
|
@@ -433,7 +530,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
433
530
|
bodyData:regBody
|
|
434
531
|
completion:^(JCOREWireFrame *responseFrame, NSError *error) {
|
|
435
532
|
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
436
|
-
if (!strongSelf || strongSelf->_connection != activeConnection) {
|
|
533
|
+
if (!strongSelf || strongSelf->_connection != activeConnection || ![strongSelf ownsCurrentPolicy]) {
|
|
437
534
|
return;
|
|
438
535
|
}
|
|
439
536
|
JCORERegisterResponse *parsed = [JCOREWireProtocol parseRegisterResponse:responseFrame];
|
|
@@ -474,7 +571,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
474
571
|
bodyData:loginBody
|
|
475
572
|
completion:^(JCOREWireFrame *responseFrame, NSError *error) {
|
|
476
573
|
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
477
|
-
if (!strongSelf || strongSelf->_connection != activeConnection) {
|
|
574
|
+
if (!strongSelf || strongSelf->_connection != activeConnection || ![strongSelf ownsCurrentPolicy]) {
|
|
478
575
|
return;
|
|
479
576
|
}
|
|
480
577
|
JCORESisEndpoint *currentEndpoint = (strongSelf->_currentEndpointIndex < strongSelf->_candidateEndpoints.count)
|
|
@@ -545,7 +642,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
545
642
|
__weak typeof(self) weakSelf = self;
|
|
546
643
|
dispatch_source_set_event_handler(timer, ^{
|
|
547
644
|
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
548
|
-
if (!strongSelf || !strongSelf->_connected || !strongSelf->_loggedIn) {
|
|
645
|
+
if (!strongSelf || ![strongSelf ownsCurrentPolicy] || !strongSelf->_connected || !strongSelf->_loggedIn) {
|
|
549
646
|
return;
|
|
550
647
|
}
|
|
551
648
|
NSData *hb = [JCOREWireProtocol buildHeartbeatPayloadWithPushStopped:[JCOREConfiguration shared].pushStopped];
|
|
@@ -574,7 +671,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
574
671
|
nw_connection_receive(connection, 1, 65536, ^(dispatch_data_t content, nw_content_context_t context, bool is_complete, nw_error_t error) {
|
|
575
672
|
(void)context;
|
|
576
673
|
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
577
|
-
if (!strongSelf || strongSelf->_connection != connection) {
|
|
674
|
+
if (!strongSelf || strongSelf->_connection != connection || ![strongSelf ownsCurrentPolicy]) {
|
|
578
675
|
return;
|
|
579
676
|
}
|
|
580
677
|
if (content != nil) {
|
|
@@ -613,6 +710,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
613
710
|
}
|
|
614
711
|
|
|
615
712
|
- (void)handleDecodedFrameLocked:(JCOREWireFrame *)frame {
|
|
713
|
+
if (![self ownsCurrentPolicy]) { return; }
|
|
616
714
|
if (frame.command == JCOREWireCommandPushMessage) {
|
|
617
715
|
JCOREPushEnvelope *envelope = [JCOREWireProtocol parsePushEnvelope:frame];
|
|
618
716
|
if (envelope != nil) {
|
|
@@ -671,46 +769,78 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
671
769
|
});
|
|
672
770
|
}
|
|
673
771
|
|
|
674
|
-
- (void)
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
772
|
+
- (void)cancelTokenRequestsLockedForCommand:(uint8_t)command {
|
|
773
|
+
NSDictionary<NSNumber *, JCOREInFlightRequest *> *snapshot = [_inFlightRequests copy];
|
|
774
|
+
for (NSNumber *key in snapshot) {
|
|
775
|
+
JCOREInFlightRequest *request = snapshot[key];
|
|
776
|
+
if (request.command != command) { continue; }
|
|
777
|
+
[request cancelTimers];
|
|
778
|
+
[_inFlightRequests removeObjectForKey:key];
|
|
779
|
+
if (request.completion) {
|
|
780
|
+
request.completion(nil, [NSError errorWithDomain:@"cn.jiguang.jpush" code:6002
|
|
781
|
+
userInfo:@{NSLocalizedDescriptionKey: @"Token report superseded"}]);
|
|
782
|
+
}
|
|
684
783
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
- (void)reportDeviceTokenLocked {
|
|
787
|
+
JCOREConfiguration *config = [JCOREConfiguration shared];
|
|
788
|
+
NSString *token = config.deviceTokenHex;
|
|
789
|
+
if (![self ownsCurrentPolicy] || !_connected || !_loggedIn || token.length == 0 ||
|
|
790
|
+
[_lastReportedDeviceTokenHex isEqualToString:token] || [_inFlightDeviceTokenHex isEqualToString:token]) { return; }
|
|
791
|
+
_lastReportedDeviceTokenHex = nil;
|
|
792
|
+
_inFlightDeviceTokenHex = [token copy];
|
|
793
|
+
NSUInteger reportGeneration = ++_deviceTokenReportGeneration;
|
|
794
|
+
[self cancelTokenRequestsLockedForCommand:JCOREWireCommandDeviceToken];
|
|
795
|
+
nw_connection_t connection = _connection;
|
|
796
|
+
NSUInteger generation = _policyGeneration;
|
|
797
|
+
uint64_t uid = config.uid;
|
|
798
|
+
[self sendRawCommandLocked:JCOREWireCommandDeviceToken version:3
|
|
799
|
+
bodyData:[JCOREWireProtocol buildDeviceTokenPayloadWithTokenHex:token]
|
|
800
|
+
completion:^(JCOREWireFrame *frame, NSError *error) {
|
|
801
|
+
if (self->_connection != connection || self->_policyGeneration != generation ||
|
|
802
|
+
![self ownsCurrentPolicy] || config.uid != uid || self->_deviceTokenReportGeneration != reportGeneration ||
|
|
803
|
+
![self->_inFlightDeviceTokenHex isEqualToString:token]) { return; }
|
|
804
|
+
self->_inFlightDeviceTokenHex = nil;
|
|
805
|
+
if (error == nil && frame != nil && frame.statusCode == 0 && [config.deviceTokenHex isEqualToString:token]) {
|
|
806
|
+
self->_lastReportedDeviceTokenHex = [token copy];
|
|
807
|
+
}
|
|
808
|
+
}];
|
|
688
809
|
}
|
|
689
810
|
|
|
690
811
|
- (void)reportVoipTokenIfNeeded {
|
|
691
|
-
dispatch_async(_sessionQueue, ^{
|
|
692
|
-
[self reportVoipTokenLocked];
|
|
693
|
-
});
|
|
812
|
+
dispatch_async(_sessionQueue, ^{ [self reportVoipTokenLocked]; });
|
|
694
813
|
}
|
|
695
814
|
|
|
696
815
|
- (void)reportVoipTokenLocked {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
816
|
+
JCOREConfiguration *config = [JCOREConfiguration shared];
|
|
817
|
+
NSString *token = config.voipTokenHex;
|
|
818
|
+
if (![self ownsCurrentPolicy] || !_connected || !_loggedIn || token.length == 0 ||
|
|
819
|
+
[_lastReportedVoipTokenHex isEqualToString:token] || [_inFlightVoipTokenHex isEqualToString:token]) { return; }
|
|
820
|
+
_lastReportedVoipTokenHex = nil;
|
|
821
|
+
_inFlightVoipTokenHex = [token copy];
|
|
822
|
+
NSUInteger reportGeneration = ++_voipTokenReportGeneration;
|
|
823
|
+
[self cancelTokenRequestsLockedForCommand:JCOREWireCommandVoipToken];
|
|
824
|
+
nw_connection_t connection = _connection;
|
|
825
|
+
NSUInteger generation = _policyGeneration;
|
|
826
|
+
uint64_t uid = config.uid;
|
|
827
|
+
[self sendRawCommandLocked:JCOREWireCommandVoipToken version:2
|
|
828
|
+
bodyData:[JCOREWireProtocol buildVoipTokenPayloadWithTokenHex:token]
|
|
829
|
+
completion:^(JCOREWireFrame *frame, NSError *error) {
|
|
830
|
+
if (self->_connection != connection || self->_policyGeneration != generation ||
|
|
831
|
+
![self ownsCurrentPolicy] || config.uid != uid || self->_voipTokenReportGeneration != reportGeneration ||
|
|
832
|
+
![self->_inFlightVoipTokenHex isEqualToString:token]) { return; }
|
|
833
|
+
self->_inFlightVoipTokenHex = nil;
|
|
834
|
+
if (error == nil && frame != nil && frame.statusCode == 0 && [config.voipTokenHex isEqualToString:token]) {
|
|
835
|
+
self->_lastReportedVoipTokenHex = [token copy];
|
|
836
|
+
}
|
|
837
|
+
}];
|
|
710
838
|
}
|
|
711
839
|
|
|
712
840
|
- (void)sendReceiptForMessageType:(uint8_t)messageType messageId:(uint64_t)messageId {
|
|
841
|
+
NSUInteger generation = [JCOREConfiguration shared].policyGeneration;
|
|
713
842
|
dispatch_async(_sessionQueue, ^{
|
|
843
|
+
if (![[JCOREConfiguration shared] allowsPolicyGeneration:generation]) { return; }
|
|
714
844
|
[self sendReceiptLockedForMessageType:messageType messageId:messageId requestId:0];
|
|
715
845
|
});
|
|
716
846
|
}
|
|
@@ -718,7 +848,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
718
848
|
- (void)sendReceiptLockedForMessageType:(uint8_t)messageType
|
|
719
849
|
messageId:(uint64_t)messageId
|
|
720
850
|
requestId:(uint16_t)requestId {
|
|
721
|
-
if (!_connected || messageId == 0) {
|
|
851
|
+
if (![self ownsCurrentPolicy] || !_connected || messageId == 0) {
|
|
722
852
|
return;
|
|
723
853
|
}
|
|
724
854
|
NSData *body = [JCOREWireProtocol buildMessageAckPayloadWithMessageType:messageType messageId:messageId];
|
|
@@ -733,7 +863,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
733
863
|
command:(uint8_t)command
|
|
734
864
|
version:(uint8_t)version
|
|
735
865
|
bodyData:(NSData *)bodyData {
|
|
736
|
-
if (!_connected || _connection == nil) {
|
|
866
|
+
if (![self ownsCurrentPolicy] || !_connected || _connection == nil) {
|
|
737
867
|
return;
|
|
738
868
|
}
|
|
739
869
|
JCOREConfiguration *config = [JCOREConfiguration shared];
|
|
@@ -743,7 +873,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
743
873
|
sessionId:_sessionId
|
|
744
874
|
uid:config.uid
|
|
745
875
|
bodyData:bodyData];
|
|
746
|
-
if (packet.length == 0) {
|
|
876
|
+
if (packet.length == 0 || ![self ownsCurrentPolicy]) {
|
|
747
877
|
return;
|
|
748
878
|
}
|
|
749
879
|
dispatch_data_t dispatchPacket = dispatch_data_create(packet.bytes,
|
|
@@ -759,11 +889,22 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
759
889
|
version:(uint8_t)version
|
|
760
890
|
bodyData:(NSData *)bodyData
|
|
761
891
|
completion:(JCORETcpResponseHandler)completion {
|
|
892
|
+
NSUInteger generation = [JCOREConfiguration shared].policyGeneration;
|
|
762
893
|
dispatch_async(_sessionQueue, ^{
|
|
894
|
+
if (![[JCOREConfiguration shared] allowsPolicyGeneration:generation] || self->_userDisconnected) {
|
|
895
|
+
if (completion) { completion(nil, [NSError errorWithDomain:@"cn.jiguang.jpush" code:6002 userInfo:nil]); }
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
763
898
|
if (command != JCOREWireCommandRegister &&
|
|
764
899
|
command != JCOREWireCommandLogin &&
|
|
765
900
|
(!self->_connected || !self->_loggedIn)) {
|
|
901
|
+
if (self->_queuedRequests.count >= 128) {
|
|
902
|
+
if (completion) { completion(nil, [NSError errorWithDomain:@"cn.jiguang.jpush" code:6002
|
|
903
|
+
userInfo:@{NSLocalizedDescriptionKey: @"Pre-login queue full"}]); }
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
766
906
|
JCOREQueuedWireRequest *queued = [[JCOREQueuedWireRequest alloc] init];
|
|
907
|
+
queued.policyGeneration = generation;
|
|
767
908
|
queued.command = command;
|
|
768
909
|
queued.version = version;
|
|
769
910
|
queued.bodyData = bodyData ?: [NSData data];
|
|
@@ -785,6 +926,10 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
785
926
|
NSArray<JCOREQueuedWireRequest *> *toSend = [_queuedRequests copy];
|
|
786
927
|
[_queuedRequests removeAllObjects];
|
|
787
928
|
for (JCOREQueuedWireRequest *item in toSend) {
|
|
929
|
+
if (![[JCOREConfiguration shared] allowsPolicyGeneration:item.policyGeneration]) {
|
|
930
|
+
if (item.completion) { item.completion(nil, [NSError errorWithDomain:@"cn.jiguang.jpush" code:6002 userInfo:nil]); }
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
788
933
|
[self sendRawCommandLocked:item.command
|
|
789
934
|
version:item.version
|
|
790
935
|
bodyData:item.bodyData
|
|
@@ -797,7 +942,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
797
942
|
bodyData:(NSData *)bodyData
|
|
798
943
|
completion:(JCORETcpResponseHandler)completion {
|
|
799
944
|
JCOREConfiguration *config = [JCOREConfiguration shared];
|
|
800
|
-
if (!_connected || _connection == nil) {
|
|
945
|
+
if (![self ownsCurrentPolicy] || !_connected || _connection == nil) {
|
|
801
946
|
if (completion != nil) {
|
|
802
947
|
NSError *err = [NSError errorWithDomain:@"cn.jiguang.jpush"
|
|
803
948
|
code:6002
|
|
@@ -823,6 +968,10 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
823
968
|
return;
|
|
824
969
|
}
|
|
825
970
|
|
|
971
|
+
if (![self ownsCurrentPolicy]) {
|
|
972
|
+
if (completion) { completion(nil, [NSError errorWithDomain:@"cn.jiguang.jpush" code:6002 userInfo:nil]); }
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
826
975
|
if (completion != nil) {
|
|
827
976
|
NSNumber *ridKey = @(rid);
|
|
828
977
|
JCOREInFlightRequest *inFlight = [[JCOREInFlightRequest alloc] init];
|
|
@@ -849,7 +998,7 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
849
998
|
return;
|
|
850
999
|
}
|
|
851
1000
|
JCOREInFlightRequest *req = strongSelf->_inFlightRequests[ridKey];
|
|
852
|
-
if (req != nil && strongSelf->_connected && strongSelf->_connection != nil) {
|
|
1001
|
+
if (req != nil && [strongSelf ownsCurrentPolicy] && strongSelf->_connected && strongSelf->_connection != nil) {
|
|
853
1002
|
dispatch_data_t resendData = dispatch_data_create(req.packetData.bytes,
|
|
854
1003
|
req.packetData.length,
|
|
855
1004
|
strongSelf->_sessionQueue,
|
|
@@ -919,8 +1068,9 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
919
1068
|
[self cancelConnectTimeoutTimerLocked];
|
|
920
1069
|
[self stopHeartbeatLocked];
|
|
921
1070
|
if (_connection != nil) {
|
|
922
|
-
|
|
1071
|
+
nw_connection_t oldConnection = _connection;
|
|
923
1072
|
_connection = nil;
|
|
1073
|
+
nw_connection_cancel(oldConnection);
|
|
924
1074
|
}
|
|
925
1075
|
[_receiveBuffer setLength:0];
|
|
926
1076
|
_connected = NO;
|
|
@@ -936,6 +1086,8 @@ NSString *const kJPFServiceErrorNotification = @"kJPFServiceErrorNotification";
|
|
|
936
1086
|
- (void)disconnect {
|
|
937
1087
|
dispatch_async(_sessionQueue, ^{
|
|
938
1088
|
self->_userDisconnected = YES;
|
|
1089
|
+
self->_attemptGeneration++;
|
|
1090
|
+
[self failQueuedRequestsLocked];
|
|
939
1091
|
[self cancelReconnectTimerLocked];
|
|
940
1092
|
BOOL wasConnected = self->_connected;
|
|
941
1093
|
self->_connecting = NO;
|
|
@@ -423,9 +423,8 @@ static NSString *JCoreReadString(NSData *data, NSUInteger *offset) {
|
|
|
423
423
|
const uint8_t *b = decodedBody.bytes;
|
|
424
424
|
if (b[0] == 0x1f && b[1] == 0x8b) {
|
|
425
425
|
NSData *unzipped = [JCORECrypto gzipDecompress:decodedBody];
|
|
426
|
-
if (unzipped
|
|
427
|
-
|
|
428
|
-
}
|
|
426
|
+
if (unzipped == nil) { return nil; }
|
|
427
|
+
decodedBody = unzipped;
|
|
429
428
|
}
|
|
430
429
|
}
|
|
431
430
|
|
|
@@ -1366,7 +1365,8 @@ static NSString *JCoreReadString(NSData *data, NSUInteger *offset) {
|
|
|
1366
1365
|
- (void)sendHttpReportItems:(NSArray<NSDictionary *> *)items
|
|
1367
1366
|
completion:(void (^)(BOOL, NSInteger))completion {
|
|
1368
1367
|
JCOREConfiguration *config = [JCOREConfiguration shared];
|
|
1369
|
-
|
|
1368
|
+
NSUInteger generation = config.policyGeneration;
|
|
1369
|
+
if (!config.policyAllowsPush || config.uid == 0 || config.appKey.length == 0) {
|
|
1370
1370
|
if (completion) {
|
|
1371
1371
|
completion(NO, -1);
|
|
1372
1372
|
}
|
|
@@ -1394,13 +1394,19 @@ static NSString *JCoreReadString(NSData *data, NSUInteger *offset) {
|
|
|
1394
1394
|
}
|
|
1395
1395
|
return;
|
|
1396
1396
|
}
|
|
1397
|
+
if (![config allowsPolicyGeneration:generation]) {
|
|
1398
|
+
if (completion) { completion(NO, 6002); }
|
|
1399
|
+
return;
|
|
1400
|
+
}
|
|
1397
1401
|
[[self.reportSession dataTaskWithRequest:req
|
|
1398
1402
|
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
|
1399
1403
|
(void)data;
|
|
1400
1404
|
NSInteger status = [response isKindOfClass:[NSHTTPURLResponse class]]
|
|
1401
1405
|
? [(NSHTTPURLResponse *)response statusCode]
|
|
1402
1406
|
: 0;
|
|
1403
|
-
BOOL
|
|
1407
|
+
BOOL current = [config allowsPolicyGeneration:generation];
|
|
1408
|
+
BOOL ok = (current && error == nil && status == 200);
|
|
1409
|
+
if (!current) { status = 6002; }
|
|
1404
1410
|
if (completion) {
|
|
1405
1411
|
completion(ok, status);
|
|
1406
1412
|
}
|
|
@@ -1410,7 +1416,8 @@ static NSString *JCoreReadString(NSData *data, NSUInteger *offset) {
|
|
|
1410
1416
|
- (void)reportBadgeValue:(NSInteger)badgeValue
|
|
1411
1417
|
completion:(void (^)(BOOL, NSInteger))completion {
|
|
1412
1418
|
JCOREConfiguration *config = [JCOREConfiguration shared];
|
|
1413
|
-
|
|
1419
|
+
NSUInteger generation = config.policyGeneration;
|
|
1420
|
+
if (!config.policyAllowsPush || config.uid == 0 || config.appKey.length == 0) {
|
|
1414
1421
|
if (completion) {
|
|
1415
1422
|
completion(NO, -1);
|
|
1416
1423
|
}
|
|
@@ -1437,13 +1444,19 @@ static NSString *JCoreReadString(NSData *data, NSUInteger *offset) {
|
|
|
1437
1444
|
}
|
|
1438
1445
|
return;
|
|
1439
1446
|
}
|
|
1447
|
+
if (![config allowsPolicyGeneration:generation]) {
|
|
1448
|
+
if (completion) { completion(NO, 6002); }
|
|
1449
|
+
return;
|
|
1450
|
+
}
|
|
1440
1451
|
[[self.reportSession dataTaskWithRequest:req
|
|
1441
1452
|
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
|
1442
1453
|
(void)data;
|
|
1443
1454
|
NSInteger status = [response isKindOfClass:[NSHTTPURLResponse class]]
|
|
1444
1455
|
? [(NSHTTPURLResponse *)response statusCode]
|
|
1445
1456
|
: 0;
|
|
1446
|
-
BOOL
|
|
1457
|
+
BOOL current = [config allowsPolicyGeneration:generation];
|
|
1458
|
+
BOOL ok = (current && error == nil && status == 200);
|
|
1459
|
+
if (!current) { status = 6002; }
|
|
1447
1460
|
if (completion) {
|
|
1448
1461
|
completion(ok, status);
|
|
1449
1462
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#import "JPUSHNotificationManager.h"
|
|
2
|
+
#import "../jcore/JCOREConfiguration.h"
|
|
2
3
|
#import <UserNotifications/UserNotifications.h>
|
|
3
4
|
#if __has_include(<UIKit/UIKit.h>)
|
|
4
5
|
#import <UIKit/UIKit.h>
|
|
@@ -325,11 +326,14 @@
|
|
|
325
326
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
|
326
327
|
willPresentNotification:(UNNotification *)notification
|
|
327
328
|
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
|
|
329
|
+
if (![JCOREConfiguration shared].policyAllowsPush) { completionHandler(UNNotificationPresentationOptionNone); return; }
|
|
330
|
+
NSUInteger generation = [JCOREConfiguration shared].policyGeneration;
|
|
328
331
|
if ([self.registerDelegate respondsToSelector:@selector(jpushNotificationCenter:willPresentNotification:withCompletionHandler:)]) {
|
|
329
332
|
[self.registerDelegate jpushNotificationCenter:center
|
|
330
333
|
willPresentNotification:notification
|
|
331
334
|
withCompletionHandler:^(NSInteger options) {
|
|
332
|
-
completionHandler(
|
|
335
|
+
completionHandler([[JCOREConfiguration shared] allowsPolicyGeneration:generation]
|
|
336
|
+
? (UNNotificationPresentationOptions)options : UNNotificationPresentationOptionNone);
|
|
333
337
|
}];
|
|
334
338
|
} else {
|
|
335
339
|
completionHandler(UNNotificationPresentationOptionBadge |
|
|
@@ -341,6 +345,7 @@
|
|
|
341
345
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
|
342
346
|
didReceiveNotificationResponse:(UNNotificationResponse *)response
|
|
343
347
|
withCompletionHandler:(void (^)(void))completionHandler {
|
|
348
|
+
if (![JCOREConfiguration shared].policyAllowsPush) { completionHandler(); return; }
|
|
344
349
|
if ([self.registerDelegate respondsToSelector:@selector(jpushNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) {
|
|
345
350
|
[self.registerDelegate jpushNotificationCenter:center
|
|
346
351
|
didReceiveNotificationResponse:response
|
|
@@ -352,6 +357,7 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
|
|
|
352
357
|
|
|
353
358
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
|
354
359
|
openSettingsForNotification:(UNNotification *)notification {
|
|
360
|
+
if (![JCOREConfiguration shared].policyAllowsPush) { return; }
|
|
355
361
|
if ([self.registerDelegate respondsToSelector:@selector(jpushNotificationCenter:openSettingsForNotification:)]) {
|
|
356
362
|
[self.registerDelegate jpushNotificationCenter:center openSettingsForNotification:notification];
|
|
357
363
|
}
|
package/ios/jpush/JPUSHService.m
CHANGED
|
@@ -69,11 +69,14 @@ static NSString *JPushHexFromData(NSData *data) {
|
|
|
69
69
|
if (remoteNotification == nil && [launchingOption isKindOfClass:[NSDictionary class]]) {
|
|
70
70
|
remoteNotification = launchingOption[@"UIApplicationLaunchOptionsRemoteNotificationKey"];
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
NSUInteger generation = config.policyGeneration;
|
|
73
|
+
if ([config allowsPolicyGeneration:generation] && [remoteNotification isKindOfClass:[NSDictionary class]]) {
|
|
73
74
|
[self handleRemoteNotification:remoteNotification];
|
|
75
|
+
NSMutableDictionary *notificationInfo = [NSMutableDictionary dictionaryWithDictionary:remoteNotification];
|
|
76
|
+
notificationInfo[@"_j_InternalPolicyGeneration"] = @(generation);
|
|
74
77
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"J_APNS_NOTIFICATION_OPENED_EVENT"
|
|
75
78
|
object:remoteNotification
|
|
76
|
-
userInfo:
|
|
79
|
+
userInfo:notificationInfo];
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
[[JCORETcpSession shared] startIfNeeded];
|
|
@@ -160,7 +163,7 @@ static NSString *JPushHexFromData(NSData *data) {
|
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
+ (void)handleRemoteNotification:(NSDictionary *)remoteInfo {
|
|
163
|
-
if (![remoteInfo isKindOfClass:[NSDictionary class]]) {
|
|
166
|
+
if (![JCOREConfiguration shared].policyAllowsPush || ![remoteInfo isKindOfClass:[NSDictionary class]]) {
|
|
164
167
|
return;
|
|
165
168
|
}
|
|
166
169
|
id msgIdObj = remoteInfo[@"_j_msgid"];
|
|
@@ -782,13 +785,8 @@ callbackSelector:(SEL)cbSelector
|
|
|
782
785
|
}
|
|
783
786
|
|
|
784
787
|
+ (void)turnOFFPush {
|
|
788
|
+
[JCORETcpSession shared];
|
|
785
789
|
[JCOREConfiguration shared].pushStopped = YES;
|
|
786
|
-
if ([[JCORETcpSession shared] isConnected] && [[JCORETcpSession shared] isLoggedIn]) {
|
|
787
|
-
NSData *body = [JCOREWireProtocol buildPushControlPayloadWithStopped:YES];
|
|
788
|
-
[[JCORETcpSession shared] sendCommand:JCOREWireCommandPushCtrl version:1 bodyData:body completion:nil];
|
|
789
|
-
} else {
|
|
790
|
-
[[JCORETcpSession shared] disconnect];
|
|
791
|
-
}
|
|
792
790
|
}
|
|
793
791
|
|
|
794
792
|
@end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-jpush",
|
|
3
|
-
"version": "6.7.0-alpha.
|
|
3
|
+
"version": "6.7.0-alpha.464",
|
|
4
4
|
"description": "Clean-room JPush and JCore React Native Nitro module for OneKey",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|