react-native-beidou 1.0.7 → 1.1.1

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 (35) hide show
  1. package/BeiDouAIDLTestPage.tsx +505 -19
  2. package/LogManager.ts +284 -0
  3. package/README.md +108 -78
  4. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  5. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  6. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  7. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  8. package/android/.idea/caches/deviceStreaming.xml +993 -0
  9. package/android/build.gradle +15 -6
  10. package/android/src/main/AndroidManifest.xml +3 -1
  11. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/BeiDouBluetoothModule.java +338 -244
  12. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/BeiDouBluetoothPackage.java +2 -2
  13. package/android/src/main/java/com/fxzs.rnbeidou/BeidouAidlHelper.java +643 -0
  14. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/ByteUtil.java +2 -2
  15. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/ChatDBManager.java +46 -46
  16. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/JsonUtil.java +4 -4
  17. package/android/src/main/java/com/fxzs.rnbeidou/LogManager.java +488 -0
  18. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/StringUtils.java +1 -1
  19. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/view/CompassManager.java +1 -1
  20. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/view/CompassView.java +2 -2
  21. package/index.ts +233 -79
  22. package/ios/BeiDouBluetoothModule.m +26 -1
  23. package/ios/BeidouBluetooth.framework/BeidouBluetooth +0 -0
  24. package/ios/BeidouBluetooth.framework/FMDB.bundle/Info.plist +0 -0
  25. package/ios/BeidouBluetooth.framework/FMDB.bundle/PrivacyInfo.xcprivacy +14 -0
  26. package/ios/BeidouBluetooth.framework/Headers/BDTLocationService.h +24 -0
  27. package/ios/BeidouBluetooth.framework/Headers/BeidouBluetooth.h +3 -1
  28. package/ios/BeidouBluetooth.framework/Info.plist +0 -0
  29. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeDirectory +0 -0
  30. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeRequirements-1 +0 -0
  31. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeResources +49 -4
  32. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeSignature +0 -0
  33. package/package.json +4 -2
  34. package/react-native-beidou.podspec +26 -0
  35. package/react-native.config.js +2 -2
@@ -1,8 +1,8 @@
1
- package com.cmcc_rn_module;
1
+ package com.fxzs.rnbeidou;
2
2
 
3
3
  import androidx.annotation.NonNull;
4
4
 
5
- import com.cmcc_rn_module.view.CompassManager;
5
+ import com.fxzs.rnbeidou.view.CompassManager;
6
6
  import com.facebook.react.ReactPackage;
7
7
  import com.facebook.react.bridge.NativeModule;
8
8
  import com.facebook.react.bridge.ReactApplicationContext;
@@ -0,0 +1,643 @@
1
+ package com.fxzs.rnbeidou;
2
+
3
+ import android.content.ComponentName;
4
+ import android.content.Context;
5
+ import android.content.Intent;
6
+ import android.content.ServiceConnection;
7
+ import android.os.IBinder;
8
+ import android.util.Log;
9
+
10
+ import androidx.annotation.Nullable;
11
+
12
+ import com.facebook.react.bridge.Promise;
13
+ import com.facebook.react.bridge.ReadableArray;
14
+ import com.facebook.react.bridge.ReactApplicationContext;
15
+ import com.facebook.react.bridge.WritableArray;
16
+ import com.facebook.react.bridge.WritableMap;
17
+ import com.facebook.react.bridge.WritableNativeArray;
18
+ import com.facebook.react.bridge.WritableNativeMap;
19
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
20
+ import com.satnav.beidouservice.BDAuthResponse;
21
+ import com.satnav.beidouservice.BDMsgDecryptResponse;
22
+ import com.satnav.beidouservice.BDMsgEncryptResponse;
23
+ import com.satnav.beidouservice.BDMsgEphemerisFileDLResponse;
24
+ import com.satnav.beidouservice.BDStatusResponse;
25
+ import com.satnav.beidouservice.IBeidouMsgAidlInterface;
26
+ import com.satnav.beidouservice.IBeidouServiceCallback;
27
+
28
+ import java.util.ArrayList;
29
+ import java.util.List;
30
+
31
+ public class BeidouAidlHelper {
32
+
33
+ @Nullable
34
+ private final ReactApplicationContext reactContext;
35
+ @Nullable
36
+ private IBeidouMsgAidlInterface beidouService;
37
+ private boolean isBeidouServiceBound = false;
38
+
39
+ @Nullable
40
+ private Promise pendingAuthPromise;
41
+ @Nullable
42
+ private Promise pendingStatusPromise;
43
+ @Nullable
44
+ private Promise pendingEphemerisPromise;
45
+
46
+ private final Object authLock = new Object();
47
+ private final Object statusLock = new Object();
48
+ private final Object ephemerisLock = new Object();
49
+
50
+ private final IBeidouServiceCallback.Stub beidouServiceCallback = new IBeidouServiceCallback.Stub() {
51
+ @Override
52
+ public void onAuthResult(int slotId, BDAuthResponse response) {
53
+ handleAuthResult(slotId, response);
54
+ }
55
+
56
+ @Override
57
+ public void onStatusResult(int slotId, BDStatusResponse response) {
58
+ handleStatusResult(slotId, response);
59
+ }
60
+
61
+ @Override
62
+ public void onEphemerisFileResult(int slotId, BDMsgEphemerisFileDLResponse response) {
63
+ handleEphemerisResult(slotId, response);
64
+ }
65
+ };
66
+
67
+ private final ServiceConnection beidouServiceConnection = new ServiceConnection() {
68
+ @Override
69
+ public void onServiceConnected(ComponentName name, IBinder service) {
70
+ beidouService = IBeidouMsgAidlInterface.Stub.asInterface(service);
71
+ isBeidouServiceBound = true;
72
+ Log.d("BeiDouService", "北斗服务连接成功");
73
+ if (beidouService != null) {
74
+ try {
75
+ beidouService.setCallback(beidouServiceCallback);
76
+ } catch (Exception e) {
77
+ Log.e("BeiDouService", "设置北斗服务回调失败: " + e.getMessage(), e);
78
+ }
79
+ }
80
+ }
81
+
82
+ @Override
83
+ public void onServiceDisconnected(ComponentName name) {
84
+ beidouService = null;
85
+ isBeidouServiceBound = false;
86
+ Log.d("BeiDouService", "北斗服务连接断开");
87
+ rejectAllPendingPromises("SERVICE_DISCONNECTED", "北斗服务连接已断开");
88
+ }
89
+ };
90
+
91
+ public BeidouAidlHelper(@Nullable ReactApplicationContext reactContext) {
92
+ this.reactContext = reactContext;
93
+ }
94
+
95
+ public void bindService(String packageName, String actionName, Promise promise) {
96
+ if (reactContext == null) {
97
+ promise.reject("CONTEXT_NULL", "React上下文不可用");
98
+ return;
99
+ }
100
+
101
+ try {
102
+ bindBeidouService(packageName, actionName);
103
+ promise.resolve(true);
104
+ } catch (Exception e) {
105
+ promise.reject("BIND_ERROR", "绑定北斗服务失败: " + e.getMessage(), e);
106
+ }
107
+ }
108
+
109
+ public void unbindService(Promise promise) {
110
+ if (reactContext == null) {
111
+ promise.reject("CONTEXT_NULL", "React上下文不可用");
112
+ return;
113
+ }
114
+
115
+ try {
116
+ unbindBeidouService();
117
+ promise.resolve(true);
118
+ } catch (Exception e) {
119
+ promise.reject("UNBIND_ERROR", "解绑北斗服务失败: " + e.getMessage(), e);
120
+ }
121
+ }
122
+
123
+ public void authenticate(int slotId, Promise promise) {
124
+ if (!ensureServiceReady(promise)) {
125
+ return;
126
+ }
127
+
128
+ Promise existing;
129
+ synchronized (authLock) {
130
+ existing = pendingAuthPromise;
131
+ pendingAuthPromise = promise;
132
+ }
133
+ rejectIfExisting(existing, "REQUEST_REPLACED", "存在未完成的鉴权请求已被新的请求覆盖");
134
+
135
+ try {
136
+ if (beidouService != null) {
137
+ beidouService.BDAuthenticate(slotId);
138
+ }
139
+ } catch (Exception e) {
140
+ clearAuthPromise(promise);
141
+ promise.reject("REMOTE_ERROR", "北斗鉴权调用失败: " + e.getMessage(), e);
142
+ }
143
+ }
144
+
145
+ public void getStatus(int slotId, Promise promise) {
146
+ if (!ensureServiceReady(promise)) {
147
+ return;
148
+ }
149
+
150
+ Promise existing;
151
+ synchronized (statusLock) {
152
+ existing = pendingStatusPromise;
153
+ pendingStatusPromise = promise;
154
+ }
155
+ rejectIfExisting(existing, "REQUEST_REPLACED", "存在未完成的状态查询请求已被新的请求覆盖");
156
+
157
+ try {
158
+ if (beidouService != null) {
159
+ beidouService.getBDMsgStatus(slotId);
160
+ }
161
+ } catch (Exception e) {
162
+ clearStatusPromise(promise);
163
+ promise.reject("REMOTE_ERROR", "获取北斗状态调用失败: " + e.getMessage(), e);
164
+ }
165
+ }
166
+
167
+ public void checkValidatedKey(int slotId, Promise promise) {
168
+ if (!ensureServiceReady(promise)) {
169
+ return;
170
+ }
171
+
172
+ try {
173
+ if (beidouService != null) {
174
+ int result = beidouService.checkValidatedKey(slotId);
175
+ promise.resolve(result);
176
+ } else {
177
+ promise.reject("SERVICE_NOT_BOUND", "北斗服务未绑定,请先调用bindBeidouServiceMethod");
178
+ }
179
+ } catch (Exception e) {
180
+ promise.reject("REMOTE_ERROR", "检查北斗密钥失败: " + e.getMessage(), e);
181
+ }
182
+ }
183
+
184
+ public void commonBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
185
+ Promise promise) {
186
+ if (!ensureServiceReady(promise)) {
187
+ return;
188
+ }
189
+
190
+ try {
191
+ List<String> receiveStringList = readableArrayToStringList(receiveList);
192
+ if (beidouService != null) {
193
+ List<BDMsgEncryptResponse> responses = beidouService.commonBDMsgEncrypt(slotId, speedType, receiveStringList,
194
+ inputMsg);
195
+ promise.resolve(encryptResponseListToWritableArray(responses));
196
+ }
197
+ } catch (Exception e) {
198
+ promise.reject("REMOTE_ERROR", "通用报文加密失败: " + e.getMessage(), e);
199
+ }
200
+ }
201
+
202
+ public void positionBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
203
+ double longitude, double latitude, Promise promise) {
204
+ if (!ensureServiceReady(promise)) {
205
+ return;
206
+ }
207
+
208
+ try {
209
+ List<String> receiveStringList = readableArrayToStringList(receiveList);
210
+ if (beidouService != null) {
211
+ List<BDMsgEncryptResponse> responses = beidouService.positionBDMsgEncrypt(slotId, speedType, receiveStringList,
212
+ inputMsg, longitude, latitude);
213
+ promise.resolve(encryptResponseListToWritableArray(responses));
214
+ }
215
+ } catch (Exception e) {
216
+ promise.reject("REMOTE_ERROR", "位置报文加密失败: " + e.getMessage(), e);
217
+ }
218
+ }
219
+
220
+ public void commonEmergencyBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
221
+ Promise promise) {
222
+ if (!ensureServiceReady(promise)) {
223
+ return;
224
+ }
225
+
226
+ try {
227
+ List<String> receiveStringList = readableArrayToStringList(receiveList);
228
+ if (beidouService != null) {
229
+ List<BDMsgEncryptResponse> responses = beidouService.commonEmergencyBDMsgEncrypt(slotId, speedType, receiveStringList,
230
+ inputMsg);
231
+ promise.resolve(encryptResponseListToWritableArray(responses));
232
+ }
233
+ } catch (Exception e) {
234
+ promise.reject("REMOTE_ERROR", "应急通用报文加密失败: " + e.getMessage(), e);
235
+ }
236
+ }
237
+
238
+ public void positionEmergencyBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
239
+ double longitude, double latitude, Promise promise) {
240
+ if (!ensureServiceReady(promise)) {
241
+ return;
242
+ }
243
+
244
+ try {
245
+ List<String> receiveStringList = readableArrayToStringList(receiveList);
246
+ if (beidouService != null) {
247
+ List<BDMsgEncryptResponse> responses = beidouService.positionEmergencyBDMsgEncrypt(slotId, speedType,
248
+ receiveStringList, inputMsg, longitude, latitude);
249
+ promise.resolve(encryptResponseListToWritableArray(responses));
250
+ }
251
+ } catch (Exception e) {
252
+ promise.reject("REMOTE_ERROR", "应急位置报文加密失败: " + e.getMessage(), e);
253
+ }
254
+ }
255
+
256
+ public void commonRichMediaBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String msgType,
257
+ @Nullable ReadableArray inputRichMediaData, Promise promise) {
258
+ if (!ensureServiceReady(promise)) {
259
+ return;
260
+ }
261
+
262
+ try {
263
+ List<String> receiveStringList = readableArrayToStringList(receiveList);
264
+ byte[] richMediaData = readableArrayToByteArray(inputRichMediaData);
265
+ if (beidouService != null) {
266
+ List<BDMsgEncryptResponse> responses = beidouService.commonRichMediaBDMsgEncrypt(slotId, speedType,
267
+ receiveStringList, msgType, richMediaData);
268
+ promise.resolve(encryptResponseListToWritableArray(responses));
269
+ }
270
+ } catch (Exception e) {
271
+ promise.reject("REMOTE_ERROR", "富媒体通用报文加密失败: " + e.getMessage(), e);
272
+ }
273
+ }
274
+
275
+ public void positionRichMediaBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String msgType,
276
+ @Nullable ReadableArray inputRichMediaData, double longitude, double latitude,
277
+ Promise promise) {
278
+ if (!ensureServiceReady(promise)) {
279
+ return;
280
+ }
281
+
282
+ try {
283
+ List<String> receiveStringList = readableArrayToStringList(receiveList);
284
+ byte[] richMediaData = readableArrayToByteArray(inputRichMediaData);
285
+ if (beidouService != null) {
286
+ List<BDMsgEncryptResponse> responses = beidouService.positionRichMediaBDMsgEncrypt(slotId, speedType,
287
+ receiveStringList, msgType, richMediaData, longitude, latitude);
288
+ promise.resolve(encryptResponseListToWritableArray(responses));
289
+ }
290
+ } catch (Exception e) {
291
+ promise.reject("REMOTE_ERROR", "富媒体位置报文加密失败: " + e.getMessage(), e);
292
+ }
293
+ }
294
+
295
+ public void commonRichMediaAndTextBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String text,
296
+ String msgType, @Nullable ReadableArray inputRichMediaData, Promise promise) {
297
+ if (!ensureServiceReady(promise)) {
298
+ return;
299
+ }
300
+
301
+ try {
302
+ List<String> receiveStringList = readableArrayToStringList(receiveList);
303
+ byte[] richMediaData = readableArrayToByteArray(inputRichMediaData);
304
+ if (beidouService != null) {
305
+ List<BDMsgEncryptResponse> responses = beidouService.commonRichMediaAndTextBDMsgEncrypt(slotId, speedType,
306
+ receiveStringList, text, msgType, richMediaData);
307
+ promise.resolve(encryptResponseListToWritableArray(responses));
308
+ }
309
+ } catch (Exception e) {
310
+ promise.reject("REMOTE_ERROR", "图文混排通用报文加密失败: " + e.getMessage(), e);
311
+ }
312
+ }
313
+
314
+ public void positionRichMediaAndTextBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String text,
315
+ String msgType, @Nullable ReadableArray inputRichMediaData, double longitude,
316
+ double latitude, Promise promise) {
317
+ if (!ensureServiceReady(promise)) {
318
+ return;
319
+ }
320
+
321
+ try {
322
+ List<String> receiveStringList = readableArrayToStringList(receiveList);
323
+ byte[] richMediaData = readableArrayToByteArray(inputRichMediaData);
324
+ if (beidouService != null) {
325
+ List<BDMsgEncryptResponse> responses = beidouService.positionRichMediaAndTextBDMsgEncrypt(slotId, speedType,
326
+ receiveStringList, text, msgType, richMediaData, longitude, latitude);
327
+ promise.resolve(encryptResponseListToWritableArray(responses));
328
+ }
329
+ } catch (Exception e) {
330
+ promise.reject("REMOTE_ERROR", "图文混排位置报文加密失败: " + e.getMessage(), e);
331
+ }
332
+ }
333
+
334
+ public void mailboxQueryEncrypt(int slotId, Promise promise) {
335
+ if (!ensureServiceReady(promise)) {
336
+ return;
337
+ }
338
+
339
+ try {
340
+ if (beidouService != null) {
341
+ BDMsgEncryptResponse response = beidouService.BDMailboxQueryEncrypt(slotId);
342
+ promise.resolve(createEncryptResponseMap(response));
343
+ }
344
+ } catch (Exception e) {
345
+ promise.reject("REMOTE_ERROR", "信箱查询加密失败: " + e.getMessage(), e);
346
+ }
347
+ }
348
+
349
+ public void emergencyMailboxQueryEncrypt(int slotId, String replyMobile, Promise promise) {
350
+ if (!ensureServiceReady(promise)) {
351
+ return;
352
+ }
353
+
354
+ try {
355
+ if (beidouService != null) {
356
+ BDMsgEncryptResponse response = beidouService.EmergencyBDMailboxQueryEncrypt(slotId, replyMobile);
357
+ promise.resolve(createEncryptResponseMap(response));
358
+ }
359
+ } catch (Exception e) {
360
+ promise.reject("REMOTE_ERROR", "应急信箱查询加密失败: " + e.getMessage(), e);
361
+ }
362
+ }
363
+
364
+ public void decryptMessage(int slotId, @Nullable ReadableArray msg, int len, Promise promise) {
365
+ if (!ensureServiceReady(promise)) {
366
+ return;
367
+ }
368
+
369
+ try {
370
+ byte[] msgBytes = readableArrayToByteArray(msg);
371
+ if (beidouService != null) {
372
+ BDMsgDecryptResponse response = beidouService.BDMsgDecrypt(slotId, msgBytes, len);
373
+ promise.resolve(createDecryptResponseMap(response));
374
+ }
375
+ } catch (Exception e) {
376
+ promise.reject("REMOTE_ERROR", "报文解密失败: " + e.getMessage(), e);
377
+ }
378
+ }
379
+
380
+ public void downloadEphemerisFile(int slotId, String type, String version, Promise promise) {
381
+ if (!ensureServiceReady(promise)) {
382
+ return;
383
+ }
384
+
385
+ Promise existing;
386
+ synchronized (ephemerisLock) {
387
+ existing = pendingEphemerisPromise;
388
+ pendingEphemerisPromise = promise;
389
+ }
390
+ rejectIfExisting(existing, "REQUEST_REPLACED", "存在未完成的星历文件下载请求已被新的请求覆盖");
391
+
392
+ try {
393
+ if (beidouService != null) {
394
+ beidouService.DLEphemerisFile(slotId, type, version);
395
+ }
396
+ } catch (Exception e) {
397
+ clearEphemerisPromise(promise);
398
+ promise.reject("REMOTE_ERROR", "下载星历文件调用失败: " + e.getMessage(), e);
399
+ }
400
+ }
401
+
402
+ private void bindBeidouService(String packageName, String actionName) {
403
+ if (!isBeidouServiceBound && reactContext != null) {
404
+ Intent intent = new Intent();
405
+ intent.setComponent(new ComponentName(packageName, actionName));
406
+ boolean result = reactContext.bindService(intent, beidouServiceConnection, Context.BIND_AUTO_CREATE);
407
+ Log.d("BeiDouService", "绑定北斗服务结果: " + result + ", 包名: " + packageName + ", 类名: " + actionName);
408
+ }
409
+ }
410
+
411
+ private void unbindBeidouService() {
412
+ if (isBeidouServiceBound && reactContext != null) {
413
+ reactContext.unbindService(beidouServiceConnection);
414
+ beidouService = null;
415
+ isBeidouServiceBound = false;
416
+ Log.d("BeiDouService", "解绑北斗服务成功");
417
+ rejectAllPendingPromises("SERVICE_UNBOUND", "北斗服务已解绑");
418
+ }
419
+ }
420
+
421
+ private boolean ensureServiceReady(Promise promise) {
422
+ if (!isBeidouServiceBound || beidouService == null) {
423
+ promise.reject("SERVICE_NOT_BOUND", "北斗服务未绑定,请先调用bindBeidouServiceMethod");
424
+ return false;
425
+ }
426
+ return true;
427
+ }
428
+
429
+ private void handleAuthResult(int slotId, @Nullable BDAuthResponse response) {
430
+ WritableMap result = createAuthResultMap(slotId, response);
431
+ Promise promise;
432
+ synchronized (authLock) {
433
+ promise = pendingAuthPromise;
434
+ pendingAuthPromise = null;
435
+ }
436
+ if (promise != null) {
437
+ resolvePromiseOnUiThread(promise, result);
438
+ }
439
+ sendEventToJS("BeiDouAuthResult", createAuthResultMap(slotId, response));
440
+ }
441
+
442
+ private void handleStatusResult(int slotId, @Nullable BDStatusResponse response) {
443
+ WritableMap result = createStatusResultMap(slotId, response);
444
+ Promise promise;
445
+ synchronized (statusLock) {
446
+ promise = pendingStatusPromise;
447
+ pendingStatusPromise = null;
448
+ }
449
+ if (promise != null) {
450
+ resolvePromiseOnUiThread(promise, result);
451
+ }
452
+ sendEventToJS("BeiDouStatusResult", createStatusResultMap(slotId, response));
453
+ }
454
+
455
+ private void handleEphemerisResult(int slotId, @Nullable BDMsgEphemerisFileDLResponse response) {
456
+ WritableMap result = createEphemerisResultMap(slotId, response);
457
+ Promise promise;
458
+ synchronized (ephemerisLock) {
459
+ promise = pendingEphemerisPromise;
460
+ pendingEphemerisPromise = null;
461
+ }
462
+ if (promise != null) {
463
+ resolvePromiseOnUiThread(promise, result);
464
+ }
465
+ sendEventToJS("BeiDouEphemerisResult", createEphemerisResultMap(slotId, response));
466
+ }
467
+
468
+ private void resolvePromiseOnUiThread(final Promise promise, final WritableMap value) {
469
+ runOnUiQueueThread(() -> promise.resolve(value));
470
+ }
471
+
472
+ private void rejectPromiseOnUiThread(final Promise promise, final String code, final String message) {
473
+ runOnUiQueueThread(() -> promise.reject(code, message));
474
+ }
475
+
476
+ private void runOnUiQueueThread(Runnable runnable) {
477
+ if (reactContext != null) {
478
+ reactContext.runOnUiQueueThread(runnable);
479
+ } else {
480
+ runnable.run();
481
+ }
482
+ }
483
+
484
+ private void sendEventToJS(String eventName, @Nullable WritableMap params) {
485
+ if (reactContext == null) {
486
+ return;
487
+ }
488
+ WritableMap safeParams = params != null ? params : new WritableNativeMap();
489
+ runOnUiQueueThread(() -> reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
490
+ .emit(eventName, safeParams));
491
+ }
492
+
493
+ private WritableMap createAuthResultMap(int slotId, @Nullable BDAuthResponse response) {
494
+ WritableMap map = new WritableNativeMap();
495
+ map.putInt("slotId", slotId);
496
+ map.putInt("code", response != null ? response.code : -1);
497
+ map.putString("statusMsg", response != null ? response.statusMsg : null);
498
+ return map;
499
+ }
500
+
501
+ private WritableMap createStatusResultMap(int slotId, @Nullable BDStatusResponse response) {
502
+ WritableMap map = new WritableNativeMap();
503
+ map.putInt("slotId", slotId);
504
+ map.putInt("code", response != null ? response.code : -1);
505
+ map.putString("statusMsg", response != null ? response.statusMsg : null);
506
+ map.putInt("msgQuotaRemain", response != null ? response.msgQuotaRemain : -1);
507
+ map.putInt("userOpenStatus", response != null ? response.userOpenStatus : -1);
508
+ return map;
509
+ }
510
+
511
+ private WritableMap createEphemerisResultMap(int slotId, @Nullable BDMsgEphemerisFileDLResponse response) {
512
+ WritableMap map = new WritableNativeMap();
513
+ map.putInt("slotId", slotId);
514
+ map.putInt("code", response != null ? response.code : -1);
515
+ map.putString("statusMsg", response != null ? response.statusMsg : null);
516
+ map.putString("version", response != null ? response.version : null);
517
+ map.putString("ephemerisZipFileName", response != null ? response.ephemerisZipFileName : null);
518
+ map.putArray("ephemerisZipFile", response != null ? byteArrayToWritableArray(response.ephemerisZipFile)
519
+ : new WritableNativeArray());
520
+ return map;
521
+ }
522
+
523
+ private WritableMap createDecryptResponseMap(@Nullable BDMsgDecryptResponse response) {
524
+ WritableMap map = new WritableNativeMap();
525
+ map.putInt("statusMsg", response != null ? response.statusMsg : -1);
526
+ map.putInt("isRemainMsg", response != null ? response.isRemainMsg : -1);
527
+ map.putString("rcvMobile", response != null ? response.rcvMobile : null);
528
+ map.putString("data", response != null ? response.data : null);
529
+ return map;
530
+ }
531
+
532
+ private WritableMap createEncryptResponseMap(@Nullable BDMsgEncryptResponse response) {
533
+ WritableMap map = new WritableNativeMap();
534
+ if (response != null) {
535
+ map.putInt("code", response.code);
536
+ map.putString("statusMsg", response.statusMsg);
537
+ map.putArray("data", byteArrayToWritableArray(response.data));
538
+ map.putString("sendMobile", response.sendMobile);
539
+ map.putInt("len", response.len);
540
+ } else {
541
+ map.putInt("code", -1);
542
+ map.putString("statusMsg", null);
543
+ map.putArray("data", new WritableNativeArray());
544
+ map.putString("sendMobile", null);
545
+ map.putInt("len", -1);
546
+ }
547
+ return map;
548
+ }
549
+
550
+ private WritableArray encryptResponseListToWritableArray(@Nullable List<BDMsgEncryptResponse> responseList) {
551
+ WritableArray array = new WritableNativeArray();
552
+ if (responseList != null) {
553
+ for (BDMsgEncryptResponse response : responseList) {
554
+ array.pushMap(createEncryptResponseMap(response));
555
+ }
556
+ }
557
+ return array;
558
+ }
559
+
560
+ private WritableArray byteArrayToWritableArray(@Nullable byte[] byteArray) {
561
+ WritableArray array = new WritableNativeArray();
562
+ if (byteArray != null) {
563
+ for (byte b : byteArray) {
564
+ array.pushInt(b & 0xFF);
565
+ }
566
+ }
567
+ return array;
568
+ }
569
+
570
+ private List<String> readableArrayToStringList(@Nullable ReadableArray readableArray) {
571
+ List<String> list = new ArrayList<>();
572
+ if (readableArray == null) {
573
+ return list;
574
+ }
575
+ for (int i = 0; i < readableArray.size(); i++) {
576
+ list.add(readableArray.getString(i));
577
+ }
578
+ return list;
579
+ }
580
+
581
+ private byte[] readableArrayToByteArray(@Nullable ReadableArray readableArray) {
582
+ if (readableArray == null) {
583
+ return new byte[0];
584
+ }
585
+ byte[] bytes = new byte[readableArray.size()];
586
+ for (int i = 0; i < readableArray.size(); i++) {
587
+ bytes[i] = (byte) readableArray.getInt(i);
588
+ }
589
+ return bytes;
590
+ }
591
+
592
+ private void rejectAllPendingPromises(String code, String message) {
593
+ Promise auth;
594
+ Promise status;
595
+ Promise ephemeris;
596
+ synchronized (authLock) {
597
+ auth = pendingAuthPromise;
598
+ pendingAuthPromise = null;
599
+ }
600
+ synchronized (statusLock) {
601
+ status = pendingStatusPromise;
602
+ pendingStatusPromise = null;
603
+ }
604
+ synchronized (ephemerisLock) {
605
+ ephemeris = pendingEphemerisPromise;
606
+ pendingEphemerisPromise = null;
607
+ }
608
+ rejectIfExisting(auth, code, message);
609
+ rejectIfExisting(status, code, message);
610
+ rejectIfExisting(ephemeris, code, message);
611
+ }
612
+
613
+ private void rejectIfExisting(@Nullable Promise promise, String code, String message) {
614
+ if (promise != null) {
615
+ rejectPromiseOnUiThread(promise, code, message);
616
+ }
617
+ }
618
+
619
+ private void clearAuthPromise(Promise expected) {
620
+ synchronized (authLock) {
621
+ if (pendingAuthPromise == expected) {
622
+ pendingAuthPromise = null;
623
+ }
624
+ }
625
+ }
626
+
627
+ private void clearStatusPromise(Promise expected) {
628
+ synchronized (statusLock) {
629
+ if (pendingStatusPromise == expected) {
630
+ pendingStatusPromise = null;
631
+ }
632
+ }
633
+ }
634
+
635
+ private void clearEphemerisPromise(Promise expected) {
636
+ synchronized (ephemerisLock) {
637
+ if (pendingEphemerisPromise == expected) {
638
+ pendingEphemerisPromise = null;
639
+ }
640
+ }
641
+ }
642
+ }
643
+
@@ -1,4 +1,4 @@
1
- package com.cmcc_rn_module;
1
+ package com.fxzs.rnbeidou;
2
2
 
3
3
  import android.util.Log;
4
4
 
@@ -10,7 +10,7 @@ public class ByteUtil {
10
10
 
11
11
  /**
12
12
  * 重复字符生成字符串的兼容方法(替代 String.repeat())
13
- *
13
+ *
14
14
  * @param ch 要重复的字符
15
15
  * @param count 重复次数
16
16
  * @return 重复字符组成的字符串