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,4 +1,4 @@
1
- package com.cmcc_rn_module;
1
+ package com.fxzs.rnbeidou;
2
2
 
3
3
  import android.Manifest;
4
4
  import android.bluetooth.BluetoothAdapter;
@@ -13,6 +13,9 @@ import android.os.Build;
13
13
  import android.util.Log;
14
14
  import android.location.Location;
15
15
  import android.location.LocationManager;
16
+ import android.telephony.SubscriptionInfo;
17
+ import android.telephony.SubscriptionManager;
18
+ import android.telephony.TelephonyManager;
16
19
 
17
20
  import androidx.annotation.NonNull;
18
21
  import androidx.annotation.Nullable;
@@ -31,7 +34,10 @@ import com.facebook.react.bridge.ReactContext;
31
34
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
32
35
  import com.facebook.react.bridge.ReactMethod;
33
36
  import com.facebook.react.bridge.WritableMap;
37
+ import com.facebook.react.bridge.ReadableArray;
38
+ import com.facebook.react.bridge.WritableArray;
34
39
  import com.facebook.react.bridge.WritableNativeMap;
40
+ import com.facebook.react.bridge.WritableNativeArray;
35
41
  import com.facebook.react.modules.core.DeviceEventManagerModule;
36
42
 
37
43
  import org.json.JSONException;
@@ -40,29 +46,15 @@ import java.util.Arrays;
40
46
  import java.util.Base64;
41
47
  import java.util.Map;
42
48
  import java.util.Objects;
43
- import java.util.List;
44
49
  import java.util.ArrayList;
45
-
46
- // 北斗AIDL服务相关导入
47
- import com.satnav.beidouservice.IBeidouMsgAidlInterface;
48
- import com.satnav.beidouservice.BDStatusResponse;
49
- import com.satnav.beidouservice.BDMsgEncryptResponse;
50
- import com.satnav.beidouservice.BDMsgDecryptResponse;
51
- import com.satnav.beidouservice.BDMsgEphemerisFileDLResponse;
52
- import android.content.ServiceConnection;
53
- import android.content.ComponentName;
54
- import android.content.Intent;
55
- import android.os.IBinder;
56
- import com.facebook.react.bridge.ReadableArray;
57
- import com.facebook.react.bridge.WritableArray;
58
- import com.facebook.react.bridge.WritableNativeArray;
50
+ import java.util.List;
59
51
 
60
52
  public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
61
53
  private ReactContext reactContext;
54
+ private LogManager logger;
62
55
 
63
- // 北斗AIDL服务相关字段
64
- private IBeidouMsgAidlInterface beidouService;
65
- private boolean isBeidouServiceBound = false;
56
+ // 北斗AIDL服务辅助类
57
+ private final BeidouAidlHelper beidouAidlHelper;
66
58
 
67
59
  @NonNull
68
60
  @Override
@@ -73,10 +65,21 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
73
65
  public BeiDouBluetoothModule(@Nullable ReactApplicationContext reactContext) {
74
66
  super(reactContext);
75
67
  this.reactContext = reactContext;
68
+ this.beidouAidlHelper = new BeidouAidlHelper(reactContext);
69
+
70
+ // 初始化日志管理器
71
+ this.logger = LogManager.getInstance();
72
+ // 默认配置:根据ApplicationInfo.FLAG_DEBUGGABLE判断是否为Debug模式
73
+ boolean isDebug = reactContext != null &&
74
+ (reactContext.getApplicationInfo().flags & android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) != 0;
75
+ logger.initialize(reactContext, isDebug, true, null);
76
+
77
+ logger.i("BeiDouBluetoothModule", "BeiDouBluetoothModule initialized - Debug: " + isDebug);
78
+
76
79
  BluetoothSDK.getInstance(reactContext).setPushCallback(new BluetoothPushCallback() {
77
80
  @Override
78
81
  public void onDevicePush(String deviceNo, String data, int cmd) {
79
- Log.d("BeiDouBluetoothModule","收到设备推送消息: "+data);
82
+ logger.d("BeiDouBluetoothModule", "收到设备推送消息: " + data);
80
83
  // 处理接收到的数据
81
84
  WritableMap writableMap = new WritableNativeMap();
82
85
  writableMap.putInt("type", 0);
@@ -105,9 +108,9 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
105
108
  long timeInterval = timestamp.longValue();
106
109
  boolean send = isSend != null ? isSend : false;
107
110
  getChatDBManager().insertMessage(content, phone, send, timeInterval);
108
- Log.d("BeiDouBluetoothModule", String.format("插入消息成功 - 手机号: %s, 是否发送: %b", phone, send));
111
+ logger.d("BeiDouBluetoothModule", String.format("插入消息成功 - 手机号: %s, 是否发送: %b", phone, send));
109
112
  } catch (Exception e) {
110
- Log.e("BeiDouBluetoothModule", "插入消息失败: " + e.getMessage());
113
+ logger.e("BeiDouBluetoothModule", "插入消息失败: " + e.getMessage(), e);
111
114
  }
112
115
  }
113
116
 
@@ -174,28 +177,28 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
174
177
  public void connectToDeviceFromCloudDeviceNO(String deviceNO, Double a, Promise promise) {
175
178
  if (StringUtils.isEmpty(deviceNO)) {
176
179
  Log.e("BluetoothSDK", "connectToDeviceFromCloudDeviceNO: deviceNo isEmpty");
177
- promise.resolve("fail");
180
+ promise.resolve("0");
178
181
  return;
179
182
  }
180
183
  BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
181
184
  BluetoothConnectionCallback connectionCallback = new BluetoothConnectionCallback() {
182
185
  @Override
183
186
  public void onConnected(String deviceNo) {
184
- Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: ok");
185
- promise.resolve("ok");
187
+ Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: 1");
188
+ promise.resolve("1");
186
189
  }
187
190
 
188
191
  @Override
189
192
  public void onConnectionFailed(String deviceNo, int errorCode, String errorMessage) {
190
- Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: fail");
191
- promise.resolve("fail");
193
+ Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: 0");
194
+ promise.resolve("0");
192
195
  }
193
196
 
194
197
  @Override
195
198
  public void onDisconnected(String deviceNo) {
196
199
  // 连接过程中意外断开
197
- Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: fail");
198
- promise.resolve("fail");
200
+ Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: 0");
201
+ promise.resolve("0");
199
202
  }
200
203
 
201
204
  @Override
@@ -366,7 +369,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
366
369
  // }
367
370
  @ReactMethod
368
371
  public void writeData(String randomString, String deviceNo, Integer command, Integer attrType,
369
- Callback writeCallback) {
372
+ Callback writeCallback) {
370
373
  BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
371
374
  Log.d("BluetoothSDK", "收到写入请求" + command + " " + attrType + " " + randomString);
372
375
  BluetoothDataCallback dataCallback = new BluetoothDataCallback() {
@@ -384,7 +387,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
384
387
  @Override
385
388
  public void onDataReceived(String deviceNo, byte[] data, int dataType) {
386
389
  // 处理接收到的数据
387
- // byte[] cipher = Arrays.copyOfRange(data, 4, data.length);
390
+ // byte[] cipher = Arrays.copyOfRange(data, 4, data.length);
388
391
  String message = Base64.getEncoder().encodeToString(data);
389
392
 
390
393
  WritableMap writableMap = new WritableNativeMap();
@@ -413,7 +416,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
413
416
 
414
417
  @ReactMethod
415
418
  public void writeInfo(@Nullable String base64Payload, String deviceNO, Integer command, Integer opCode,
416
- Integer attrType, Boolean encrypted, Promise promise) {
419
+ Integer attrType, Boolean encrypted, Promise promise) {
417
420
  try {
418
421
  BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
419
422
 
@@ -438,7 +441,8 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
438
441
  int attrTypeValue = attrType & 0xFFFF;
439
442
  boolean isEncrypted = encrypted != null ? encrypted : false;
440
443
 
441
- Log.d("BluetoothSDK", String.format("writeInfo - deviceNO: %s, command: 0x%02X, opCode: 0x%02X, attrType: 0x%04X, encrypted: %b",
444
+ Log.d("BluetoothSDK", String.format(
445
+ "writeInfo - deviceNO: %s, command: 0x%02X, opCode: 0x%02X, attrType: 0x%04X, encrypted: %b",
442
446
  deviceNO, commandValue, opCodeValue, attrTypeValue, isEncrypted));
443
447
 
444
448
  // 设置数据回调
@@ -447,10 +451,10 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
447
451
  public void onDataWriteSuccess(String deviceNo, byte[] data) {
448
452
  Log.d("BluetoothSDK", "writeInfo写入成功");
449
453
  // 返回成功结果
450
- // WritableMap resDict = new WritableNativeMap();
451
- // resDict.putInt("type", 1);
452
- // resDict.putString("data", "");
453
- // promise.resolve(resDict);
454
+ // WritableMap resDict = new WritableNativeMap();
455
+ // resDict.putInt("type", 1);
456
+ // resDict.putString("data", "");
457
+ // promise.resolve(resDict);
454
458
  }
455
459
 
456
460
  @Override
@@ -486,7 +490,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
486
490
 
487
491
  // 调用SDK写入数据
488
492
  String dataString = Base64.getEncoder().encodeToString(decodedData);
489
- instance.writeData(dataString, deviceNO, commandValue, attrTypeValue,opCodeValue, isEncrypted);
493
+ instance.writeData(dataString, deviceNO, commandValue, attrTypeValue, opCodeValue, isEncrypted);
490
494
 
491
495
  } catch (Exception e) {
492
496
  Log.e("BluetoothSDK", "writeInfo异常: " + e.getMessage());
@@ -496,7 +500,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
496
500
 
497
501
  @ReactMethod
498
502
  public void writeValueInfo(String randomString, String deviceNo, Integer command, Integer attrType, Integer value,
499
- Callback writeCallback) {
503
+ Callback writeCallback) {
500
504
  // BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
501
505
  // Log.d(BluetoothSDK.TAG, "收到写入请求" + command +" "+attrType+" "+randomString);
502
506
  // Callback callback = args -> {
@@ -532,8 +536,6 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
532
536
  BluetoothSDK.getInstance(reactContext).disconnectDevice(deviceNo, disConnectCallback);
533
537
  }
534
538
 
535
-
536
-
537
539
  @ReactMethod
538
540
  public void fetchCurrentWifiName(Callback callback) {
539
541
  String wifiName = "未连接";
@@ -601,256 +603,242 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
601
603
  callback.invoke(wifiName);
602
604
  }
603
605
 
604
- // ================== 北斗AIDL服务相关方法 ==================
606
+ /**
607
+ * 获取当前设备的SIM卡信息列表
608
+ */
609
+ @ReactMethod
610
+ public void getSimCardList(Promise promise) {
611
+ try {
612
+ if (reactContext == null) {
613
+ promise.reject("CONTEXT_NULL", "React上下文不可用");
614
+ return;
615
+ }
605
616
 
606
- private final ServiceConnection beidouServiceConnection = new ServiceConnection() {
607
- @Override
608
- public void onServiceConnected(ComponentName name, IBinder service) {
609
- beidouService = IBeidouMsgAidlInterface.Stub.asInterface(service);
610
- isBeidouServiceBound = true;
611
- Log.d("BeiDouService", "北斗服务连接成功");
612
- }
617
+ boolean hasReadPhoneStatePermission = ContextCompat.checkSelfPermission(reactContext,
618
+ Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
613
619
 
614
- @Override
615
- public void onServiceDisconnected(ComponentName name) {
616
- beidouService = null;
617
- isBeidouServiceBound = false;
618
- Log.d("BeiDouService", "北斗服务连接断开");
619
- }
620
- };
620
+ if (!hasReadPhoneStatePermission) {
621
+ promise.reject("PERMISSION_DENIED", "缺少READ_PHONE_STATE权限");
622
+ return;
623
+ }
621
624
 
622
- private void bindBeidouService(String packageName, String actionName) {
623
- if (!isBeidouServiceBound && reactContext != null) {
624
- Intent intent = new Intent();
625
- // 使用ComponentName方式,actionName作为className
626
- intent.setComponent(new android.content.ComponentName(packageName, actionName));
627
- try {
628
- boolean result = reactContext.bindService(intent, beidouServiceConnection, Context.BIND_AUTO_CREATE);
629
- Log.d("BeiDouService", "绑定北斗服务结果: " + result + ", 包名: " + packageName + ", 类名: " + actionName);
630
- } catch (Exception e) {
631
- Log.e("BeiDouService", "绑定北斗服务失败: " + e.getMessage());
625
+ boolean hasReadPhoneNumbersPermission = true;
626
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
627
+ hasReadPhoneNumbersPermission = ContextCompat.checkSelfPermission(reactContext,
628
+ Manifest.permission.READ_PHONE_NUMBERS) == PackageManager.PERMISSION_GRANTED;
632
629
  }
633
- }
634
- }
635
630
 
636
- private void unbindBeidouService() {
637
- if (isBeidouServiceBound && reactContext != null) {
638
- try {
639
- reactContext.unbindService(beidouServiceConnection);
640
- isBeidouServiceBound = false;
641
- Log.d("BeiDouService", "解绑北斗服务成功");
642
- } catch (Exception e) {
643
- Log.e("BeiDouService", "解绑北斗服务失败: " + e.getMessage());
631
+ WritableArray result = new WritableNativeArray();
632
+ Context context = reactContext;
633
+
634
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
635
+ SubscriptionManager subscriptionManager = (SubscriptionManager) context
636
+ .getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
637
+
638
+ if (subscriptionManager != null) {
639
+ List<SubscriptionInfo> subscriptionInfoList;
640
+ try {
641
+ subscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
642
+ } catch (SecurityException permissionException) {
643
+ promise.reject("PERMISSION_DENIED", "访问SubscriptionManager失败: " + permissionException.getMessage(),
644
+ permissionException);
645
+ return;
646
+ }
647
+
648
+ if (subscriptionInfoList != null) {
649
+ for (SubscriptionInfo info : subscriptionInfoList) {
650
+ WritableMap map = new WritableNativeMap();
651
+ CharSequence carrierName = info.getCarrierName();
652
+ CharSequence displayName = info.getDisplayName();
653
+
654
+ map.putInt("subscriptionId", info.getSubscriptionId());
655
+ map.putInt("simSlotIndex", info.getSimSlotIndex());
656
+ map.putString("carrierName", carrierName != null ? carrierName.toString() : null);
657
+ map.putString("displayName", displayName != null ? displayName.toString() : null);
658
+ map.putString("countryIso", info.getCountryIso());
659
+ map.putInt("mcc", info.getMcc());
660
+ map.putInt("mnc", info.getMnc());
661
+
662
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
663
+ map.putBoolean("isEmbedded", info.isEmbedded());
664
+ map.putBoolean("isOpportunistic", info.isOpportunistic());
665
+ } else {
666
+ map.putBoolean("isEmbedded", false);
667
+ map.putBoolean("isOpportunistic", false);
668
+ }
669
+
670
+ if (hasReadPhoneNumbersPermission) {
671
+ String phoneNumber;
672
+ try {
673
+ phoneNumber = info.getNumber();
674
+ } catch (SecurityException numberException) {
675
+ phoneNumber = null;
676
+ }
677
+ map.putString("number", phoneNumber);
678
+ } else {
679
+ map.putNull("number");
680
+ }
681
+
682
+ result.pushMap(map);
683
+ }
684
+ }
685
+ }
644
686
  }
645
- }
646
- }
647
687
 
648
- // 将byte数组转换为WritableArray
649
- private WritableArray byteArrayToWritableArray(byte[] byteArray) {
650
- WritableArray array = new WritableNativeArray();
651
- if (byteArray != null) {
652
- for (byte b : byteArray) {
653
- array.pushInt(b & 0xFF); // 将byte转换为无符号int
688
+ // 如果未获取到任何SIM卡信息,尝试使用TelephonyManager做兼容
689
+ if (result.size() == 0) {
690
+ TelephonyManager telephonyManager = (TelephonyManager) context
691
+ .getSystemService(Context.TELEPHONY_SERVICE);
692
+
693
+ if (telephonyManager != null) {
694
+ WritableMap map = new WritableNativeMap();
695
+ map.putInt("subscriptionId", -1);
696
+ map.putInt("simSlotIndex", 0);
697
+ map.putString("carrierName", telephonyManager.getSimOperatorName());
698
+ map.putString("displayName", telephonyManager.getSimOperatorName());
699
+ map.putString("countryIso", telephonyManager.getSimCountryIso());
700
+
701
+ String operator = telephonyManager.getSimOperator();
702
+ if (operator != null && operator.length() >= 5) {
703
+ try {
704
+ int mcc = Integer.parseInt(operator.substring(0, 3));
705
+ int mnc = Integer.parseInt(operator.substring(3));
706
+ map.putInt("mcc", mcc);
707
+ map.putInt("mnc", mnc);
708
+ } catch (NumberFormatException ignored) {
709
+ map.putInt("mcc", -1);
710
+ map.putInt("mnc", -1);
711
+ }
712
+ } else {
713
+ map.putInt("mcc", -1);
714
+ map.putInt("mnc", -1);
715
+ }
716
+
717
+ map.putBoolean("isEmbedded", false);
718
+ map.putBoolean("isOpportunistic", false);
719
+
720
+ if (hasReadPhoneNumbersPermission) {
721
+ String phoneNumber;
722
+ try {
723
+ phoneNumber = telephonyManager.getLine1Number();
724
+ } catch (SecurityException numberException) {
725
+ phoneNumber = null;
726
+ }
727
+ map.putString("number", phoneNumber);
728
+ } else {
729
+ map.putNull("number");
730
+ }
731
+
732
+ result.pushMap(map);
733
+ }
654
734
  }
655
- }
656
- return array;
657
- }
658
735
 
659
- // 将ReadableArray转换为List<String>
660
- private List<String> readableArrayToStringList(ReadableArray readableArray) {
661
- List<String> list = new ArrayList<>();
662
- for (int i = 0; i < readableArray.size(); i++) {
663
- list.add(readableArray.getString(i));
736
+ promise.resolve(result);
737
+ } catch (SecurityException permissionException) {
738
+ promise.reject("PERMISSION_DENIED", "获取SIM卡信息权限被拒绝: " + permissionException.getMessage(),
739
+ permissionException);
740
+ } catch (Exception e) {
741
+ logger.e("BeiDouBluetoothModule", "获取SIM卡信息失败: " + e.getMessage(), e);
742
+ promise.reject("SIM_INFO_ERROR", "获取SIM卡信息失败: " + e.getMessage(), e);
664
743
  }
665
- return list;
666
744
  }
667
745
 
668
- // 将ReadableArray转换为byte数组
669
- private byte[] readableArrayToByteArray(ReadableArray readableArray) {
670
- byte[] bytes = new byte[readableArray.size()];
671
- for (int i = 0; i < readableArray.size(); i++) {
672
- bytes[i] = (byte) readableArray.getInt(i);
673
- }
674
- return bytes;
675
- }
746
+ // ================== 北斗AIDL服务相关方法 ==================
676
747
 
677
748
  @ReactMethod
678
749
  public void bindBeidouServiceMethod(String packageName, String actionName, Promise promise) {
679
- try {
680
- bindBeidouService(packageName, actionName);
681
- promise.resolve(true);
682
- } catch (Exception e) {
683
- promise.reject("BIND_ERROR", "绑定北斗服务失败: " + e.getMessage());
684
- }
750
+ beidouAidlHelper.bindService(packageName, actionName, promise);
685
751
  }
686
752
 
687
753
  @ReactMethod
688
754
  public void unbindBeidouServiceMethod(Promise promise) {
689
- try {
690
- unbindBeidouService();
691
- promise.resolve(true);
692
- } catch (Exception e) {
693
- promise.reject("UNBIND_ERROR", "解绑北斗服务失败: " + e.getMessage());
694
- }
755
+ beidouAidlHelper.unbindService(promise);
695
756
  }
696
757
 
697
758
  @ReactMethod
698
- public void BDAuthenticate(Promise promise) {
699
- if (!isBeidouServiceBound || beidouService == null) {
700
- promise.reject("SERVICE_NOT_BOUND", "北斗服务未绑定,请先调用bindBeidouServiceMethod");
701
- return;
702
- }
703
-
704
- try {
705
- boolean result = beidouService.BDAuthenticate();
706
- promise.resolve(result);
707
- } catch (Exception e) {
708
- promise.reject("REMOTE_ERROR", "北斗鉴权失败: " + e.getMessage());
709
- }
759
+ public void BDAuthenticate(int slotId, Promise promise) {
760
+ beidouAidlHelper.authenticate(slotId, promise);
710
761
  }
711
762
 
712
763
  @ReactMethod
713
- public void getBDMsgStatus(Promise promise) {
714
- if (!isBeidouServiceBound || beidouService == null) {
715
- promise.reject("SERVICE_NOT_BOUND", "北斗服务未绑定,请先调用bindBeidouServiceMethod");
716
- return;
717
- }
718
-
719
- try {
720
- BDStatusResponse response = beidouService.getBDMsgStatus();
721
- WritableMap map = new WritableNativeMap();
722
- map.putInt("code", response.code);
723
- map.putString("statusMsg", response.statusMsg);
724
- map.putInt("msgQuotaRemain", response.msgQuotaRemain);
725
- promise.resolve(map);
726
- } catch (Exception e) {
727
- promise.reject("REMOTE_ERROR", "获取北斗状态失败: " + e.getMessage());
728
- }
764
+ public void getBDMsgStatus(int slotId, Promise promise) {
765
+ beidouAidlHelper.getStatus(slotId, promise);
729
766
  }
730
767
 
731
768
  @ReactMethod
732
- public void checkValidatedKey(Promise promise) {
733
- if (!isBeidouServiceBound || beidouService == null) {
734
- promise.reject("SERVICE_NOT_BOUND", "北斗服务未绑定,请先调用bindBeidouServiceMethod");
735
- return;
736
- }
737
-
738
- try {
739
- int result = beidouService.checkValidatedKey();
740
- promise.resolve(result);
741
- } catch (Exception e) {
742
- promise.reject("REMOTE_ERROR", "检查北斗密钥失败: " + e.getMessage());
743
- }
769
+ public void checkValidatedKey(int slotId, Promise promise) {
770
+ beidouAidlHelper.checkValidatedKey(slotId, promise);
744
771
  }
745
772
 
746
773
  @ReactMethod
747
- public void commonBDMsgEncrypt(ReadableArray receiveList, String inputMsg, Promise promise) {
748
- if (!isBeidouServiceBound || beidouService == null) {
749
- promise.reject("SERVICE_NOT_BOUND", "北斗服务未绑定,请先调用bindBeidouServiceMethod");
750
- return;
751
- }
752
-
753
- try {
754
- List<String> receiveStringList = readableArrayToStringList(receiveList);
755
- BDMsgEncryptResponse response = beidouService.commonBDMsgEncrypt(receiveStringList, inputMsg);
756
-
757
- WritableMap map = new WritableNativeMap();
758
- map.putInt("code", response.code);
759
- map.putString("statusMsg", response.statusMsg);
760
- map.putArray("data", byteArrayToWritableArray(response.data));
761
- map.putString("sendMobile", response.sendMobile);
762
- promise.resolve(map);
763
- } catch (Exception e) {
764
- promise.reject("REMOTE_ERROR", "通用报文加密失败: " + e.getMessage());
765
- }
774
+ public void commonBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
775
+ Promise promise) {
776
+ beidouAidlHelper.commonBDMsgEncrypt(slotId, speedType, receiveList, inputMsg, promise);
766
777
  }
767
778
 
768
779
  @ReactMethod
769
- public void positionBDMsgEncrypt(ReadableArray receiveList, String inputMsg, double longitude, double latitude,
770
- Promise promise) {
771
- if (!isBeidouServiceBound || beidouService == null) {
772
- promise.reject("SERVICE_NOT_BOUND", "北斗服务未绑定,请先调用bindBeidouServiceMethod");
773
- return;
774
- }
775
-
776
- try {
777
- List<String> receiveStringList = readableArrayToStringList(receiveList);
778
- BDMsgEncryptResponse response = beidouService.positionBDMsgEncrypt(receiveStringList, inputMsg, longitude,
779
- latitude);
780
+ public void positionBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
781
+ double longitude, double latitude, Promise promise) {
782
+ beidouAidlHelper.positionBDMsgEncrypt(slotId, speedType, receiveList, inputMsg, longitude, latitude, promise);
783
+ }
780
784
 
781
- WritableMap map = new WritableNativeMap();
782
- map.putInt("code", response.code);
783
- map.putString("statusMsg", response.statusMsg);
784
- map.putArray("data", byteArrayToWritableArray(response.data));
785
- map.putString("sendMobile", response.sendMobile);
786
- promise.resolve(map);
787
- } catch (Exception e) {
788
- promise.reject("REMOTE_ERROR", "位置报文加密失败: " + e.getMessage());
789
- }
785
+ @ReactMethod
786
+ public void commonEmergencyBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
787
+ Promise promise) {
788
+ beidouAidlHelper.commonEmergencyBDMsgEncrypt(slotId, speedType, receiveList, inputMsg, promise);
790
789
  }
791
790
 
792
791
  @ReactMethod
793
- public void BDMailboxQueryEncrypt(Promise promise) {
794
- if (!isBeidouServiceBound || beidouService == null) {
795
- promise.reject("SERVICE_NOT_BOUND", "北斗服务未绑定,请先调用bindBeidouServiceMethod");
796
- return;
797
- }
792
+ public void positionEmergencyBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
793
+ double longitude, double latitude, Promise promise) {
794
+ beidouAidlHelper.positionEmergencyBDMsgEncrypt(slotId, speedType, receiveList, inputMsg, longitude, latitude, promise);
795
+ }
798
796
 
799
- try {
800
- BDMsgEncryptResponse response = beidouService.BDMailboxQueryEncrypt();
797
+ @ReactMethod
798
+ public void commonRichMediaBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String msgType,
799
+ @Nullable ReadableArray inputRichMediaData, Promise promise) {
800
+ beidouAidlHelper.commonRichMediaBDMsgEncrypt(slotId, speedType, receiveList, msgType, inputRichMediaData, promise);
801
+ }
801
802
 
802
- WritableMap map = new WritableNativeMap();
803
- map.putInt("code", response.code);
804
- map.putString("statusMsg", response.statusMsg);
805
- map.putArray("data", byteArrayToWritableArray(response.data));
806
- map.putString("sendMobile", response.sendMobile);
807
- promise.resolve(map);
808
- } catch (Exception e) {
809
- promise.reject("REMOTE_ERROR", "信箱查询加密失败: " + e.getMessage());
810
- }
803
+ @ReactMethod
804
+ public void positionRichMediaBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String msgType,
805
+ @Nullable ReadableArray inputRichMediaData, double longitude, double latitude, Promise promise) {
806
+ beidouAidlHelper.positionRichMediaBDMsgEncrypt(slotId, speedType, receiveList, msgType, inputRichMediaData, longitude,
807
+ latitude, promise);
811
808
  }
812
809
 
813
810
  @ReactMethod
814
- public void BDMsgDecrypt(ReadableArray msg, int len, Promise promise) {
815
- if (!isBeidouServiceBound || beidouService == null) {
816
- promise.reject("SERVICE_NOT_BOUND", "北斗服务未绑定,请先调用bindBeidouServiceMethod");
817
- return;
818
- }
811
+ public void commonRichMediaAndTextBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String text,
812
+ String msgType, @Nullable ReadableArray inputRichMediaData, Promise promise) {
813
+ beidouAidlHelper.commonRichMediaAndTextBDMsgEncrypt(slotId, speedType, receiveList, text, msgType, inputRichMediaData,
814
+ promise);
815
+ }
819
816
 
820
- try {
821
- byte[] msgBytes = readableArrayToByteArray(msg);
822
- BDMsgDecryptResponse response = beidouService.BDMsgDecrypt(msgBytes, len);
817
+ @ReactMethod
818
+ public void positionRichMediaAndTextBDMsgEncrypt(int slotId, String speedType, @Nullable ReadableArray receiveList, String text,
819
+ String msgType, @Nullable ReadableArray inputRichMediaData, double longitude, double latitude, Promise promise) {
820
+ beidouAidlHelper.positionRichMediaAndTextBDMsgEncrypt(slotId, speedType, receiveList, text, msgType, inputRichMediaData,
821
+ longitude, latitude, promise);
822
+ }
823
823
 
824
- WritableMap map = new WritableNativeMap();
825
- map.putInt("statusMsg", response.statusMsg);
826
- map.putInt("isRemainMsg", response.isRemainMsg);
827
- map.putString("rcvMobile", response.rcvMobile);
828
- map.putString("data", response.data);
829
- promise.resolve(map);
830
- } catch (Exception e) {
831
- promise.reject("REMOTE_ERROR", "报文解密失败: " + e.getMessage());
832
- }
824
+ @ReactMethod
825
+ public void BDMailboxQueryEncrypt(int slotId, Promise promise) {
826
+ beidouAidlHelper.mailboxQueryEncrypt(slotId, promise);
833
827
  }
834
828
 
835
829
  @ReactMethod
836
- public void DLEphemerisFile(String type, String version, Promise promise) {
837
- if (!isBeidouServiceBound || beidouService == null) {
838
- promise.reject("SERVICE_NOT_BOUND", "北斗服务未绑定,请先调用bindBeidouServiceMethod");
839
- return;
840
- }
830
+ public void EmergencyBDMailboxQueryEncrypt(int slotId, String replyMobile, Promise promise) {
831
+ beidouAidlHelper.emergencyMailboxQueryEncrypt(slotId, replyMobile, promise);
832
+ }
841
833
 
842
- try {
843
- BDMsgEphemerisFileDLResponse response = beidouService.DLEphemerisFile(type, version);
834
+ @ReactMethod
835
+ public void BDMsgDecrypt(int slotId, @Nullable ReadableArray msg, int len, Promise promise) {
836
+ beidouAidlHelper.decryptMessage(slotId, msg, len, promise);
837
+ }
844
838
 
845
- WritableMap map = new WritableNativeMap();
846
- map.putInt("code", response.code);
847
- map.putString("statusMsg", response.statusMsg);
848
- map.putArray("ephemerisZipFile", byteArrayToWritableArray(response.ephemerisZipFile));
849
- map.putString("version", response.version);
850
- promise.resolve(map);
851
- } catch (Exception e) {
852
- promise.reject("REMOTE_ERROR", "下载星历文件失败: " + e.getMessage());
853
- }
839
+ @ReactMethod
840
+ public void DLEphemerisFile(int slotId, String type, String version, Promise promise) {
841
+ beidouAidlHelper.downloadEphemerisFile(slotId, type, version, promise);
854
842
  }
855
843
 
856
844
  // 设置BLE密钥
@@ -899,10 +887,12 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
899
887
  Location networkLocation = null;
900
888
  try {
901
889
  gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
902
- } catch (Exception ignored) { }
890
+ } catch (Exception ignored) {
891
+ }
903
892
  try {
904
893
  networkLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
905
- } catch (Exception ignored) { }
894
+ } catch (Exception ignored) {
895
+ }
906
896
 
907
897
  Location bestLocation = null;
908
898
  if (gpsLocation != null && networkLocation != null) {
@@ -927,8 +917,112 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
927
917
  map.putDouble("timestamp", (double) bestLocation.getTime());
928
918
  promise.resolve(map);
929
919
  } catch (Exception e) {
930
- Log.e("BeiDouBluetoothModule", "获取GPS位置失败: " + e.getMessage());
920
+ logger.e("BeiDouBluetoothModule", "获取GPS位置失败: " + e.getMessage(), e);
931
921
  promise.reject("LOCATION_ERROR", "获取GPS位置失败: " + e.getMessage(), e);
932
922
  }
933
923
  }
924
+
925
+ // ================== 日志管理相关方法 ==================
926
+
927
+ /**
928
+ * 配置日志管理器
929
+ *
930
+ * @param enableFileLog 是否启用文件日志
931
+ * @param enableConsoleLog 是否启用控制台日志
932
+ * @param maxFileSize 最大文件大小(MB)
933
+ * @param maxFileCount 最大文件数量
934
+ * @param encryptionKey 加密密钥(可选)
935
+ */
936
+ @ReactMethod
937
+ public void configureLogger(boolean enableFileLog, boolean enableConsoleLog,
938
+ double maxFileSize, int maxFileCount,
939
+ @Nullable String encryptionKey, Promise promise) {
940
+ try {
941
+ // 重新初始化日志管理器
942
+ boolean isDebug = reactContext != null &&
943
+ (reactContext.getApplicationInfo().flags & android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) != 0;
944
+
945
+ logger.initialize(reactContext, isDebug, enableFileLog, encryptionKey);
946
+ logger.setLogConfig(enableFileLog, enableConsoleLog,
947
+ (long) (maxFileSize * 1024 * 1024), maxFileCount);
948
+
949
+ logger.i("BeiDouBluetoothModule", "Logger configured - FileLog: " + enableFileLog +
950
+ ", ConsoleLog: " + enableConsoleLog +
951
+ ", MaxFileSize: " + maxFileSize + "MB" +
952
+ ", MaxFileCount: " + maxFileCount +
953
+ ", Encryption: " + (encryptionKey != null));
954
+
955
+ promise.resolve(true);
956
+ } catch (Exception e) {
957
+ logger.e("BeiDouBluetoothModule", "配置日志管理器失败: " + e.getMessage(), e);
958
+ promise.reject("CONFIG_ERROR", "配置日志管理器失败: " + e.getMessage(), e);
959
+ }
960
+ }
961
+
962
+ /**
963
+ * 获取日志统计信息
964
+ */
965
+ @ReactMethod
966
+ public void getLogStats(Promise promise) {
967
+ try {
968
+ String stats = logger.getLogStats();
969
+ promise.resolve(stats);
970
+ } catch (Exception e) {
971
+ logger.e("BeiDouBluetoothModule", "获取日志统计失败: " + e.getMessage(), e);
972
+ promise.reject("STATS_ERROR", "获取日志统计失败: " + e.getMessage(), e);
973
+ }
974
+ }
975
+
976
+ /**
977
+ * 清空所有日志文件
978
+ */
979
+ @ReactMethod
980
+ public void clearAllLogs(Promise promise) {
981
+ try {
982
+ logger.clearAllLogs();
983
+ logger.i("BeiDouBluetoothModule", "所有日志文件已清空");
984
+ promise.resolve(true);
985
+ } catch (Exception e) {
986
+ logger.e("BeiDouBluetoothModule", "清空日志失败: " + e.getMessage(), e);
987
+ promise.reject("CLEAR_ERROR", "清空日志失败: " + e.getMessage(), e);
988
+ }
989
+ }
990
+
991
+ /**
992
+ * 手动记录日志
993
+ */
994
+ @ReactMethod
995
+ public void writeLog(String level, String tag, String message, Promise promise) {
996
+ try {
997
+ switch (level.toUpperCase()) {
998
+ case "VERBOSE":
999
+ case "V":
1000
+ logger.v(tag, message);
1001
+ break;
1002
+ case "DEBUG":
1003
+ case "D":
1004
+ logger.d(tag, message);
1005
+ break;
1006
+ case "INFO":
1007
+ case "I":
1008
+ logger.i(tag, message);
1009
+ break;
1010
+ case "WARN":
1011
+ case "W":
1012
+ logger.w(tag, message);
1013
+ break;
1014
+ case "ERROR":
1015
+ case "E":
1016
+ logger.e(tag, message);
1017
+ break;
1018
+ default:
1019
+ logger.i(tag, message);
1020
+ break;
1021
+ }
1022
+ promise.resolve(true);
1023
+ } catch (Exception e) {
1024
+ logger.e("BeiDouBluetoothModule", "写入日志失败: " + e.getMessage(), e);
1025
+ promise.reject("LOG_ERROR", "写入日志失败: " + e.getMessage(), e);
1026
+ }
1027
+ }
934
1028
  }