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.
- package/BeiDouAIDLTestPage.tsx +505 -19
- package/LogManager.ts +284 -0
- package/README.md +108 -78
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
- package/android/.idea/caches/deviceStreaming.xml +993 -0
- package/android/build.gradle +15 -6
- package/android/src/main/AndroidManifest.xml +3 -1
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/BeiDouBluetoothModule.java +338 -244
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/BeiDouBluetoothPackage.java +2 -2
- package/android/src/main/java/com/fxzs.rnbeidou/BeidouAidlHelper.java +643 -0
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/ByteUtil.java +2 -2
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/ChatDBManager.java +46 -46
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/JsonUtil.java +4 -4
- package/android/src/main/java/com/fxzs.rnbeidou/LogManager.java +488 -0
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/StringUtils.java +1 -1
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/view/CompassManager.java +1 -1
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/view/CompassView.java +2 -2
- package/index.ts +233 -79
- package/ios/BeiDouBluetoothModule.m +26 -1
- package/ios/BeidouBluetooth.framework/BeidouBluetooth +0 -0
- package/ios/BeidouBluetooth.framework/FMDB.bundle/Info.plist +0 -0
- package/ios/BeidouBluetooth.framework/FMDB.bundle/PrivacyInfo.xcprivacy +14 -0
- package/ios/BeidouBluetooth.framework/Headers/BDTLocationService.h +24 -0
- package/ios/BeidouBluetooth.framework/Headers/BeidouBluetooth.h +3 -1
- package/ios/BeidouBluetooth.framework/Info.plist +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeDirectory +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeRequirements-1 +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeResources +49 -4
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeSignature +0 -0
- package/package.json +4 -2
- package/react-native-beidou.podspec +26 -0
- package/react-native.config.js +2 -2
package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/BeiDouBluetoothModule.java
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package com.
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
111
|
+
logger.d("BeiDouBluetoothModule", String.format("插入消息成功 - 手机号: %s, 是否发送: %b", phone, send));
|
|
109
112
|
} catch (Exception e) {
|
|
110
|
-
|
|
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("
|
|
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:
|
|
185
|
-
promise.resolve("
|
|
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:
|
|
191
|
-
promise.resolve("
|
|
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:
|
|
198
|
-
promise.resolve("
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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(
|
|
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
|
-
//
|
|
451
|
-
//
|
|
452
|
-
//
|
|
453
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
607
|
-
|
|
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
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
Log.d("BeiDouService", "北斗服务连接断开");
|
|
619
|
-
}
|
|
620
|
-
};
|
|
620
|
+
if (!hasReadPhoneStatePermission) {
|
|
621
|
+
promise.reject("PERMISSION_DENIED", "缺少READ_PHONE_STATE权限");
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
621
624
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
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
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
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
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
748
|
-
|
|
749
|
-
|
|
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(
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
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
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
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
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
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
|
-
|
|
800
|
-
|
|
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
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
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
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
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
|
-
|
|
821
|
-
|
|
822
|
-
|
|
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
|
-
|
|
825
|
-
|
|
826
|
-
|
|
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
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
return;
|
|
840
|
-
}
|
|
830
|
+
public void EmergencyBDMailboxQueryEncrypt(int slotId, String replyMobile, Promise promise) {
|
|
831
|
+
beidouAidlHelper.emergencyMailboxQueryEncrypt(slotId, replyMobile, promise);
|
|
832
|
+
}
|
|
841
833
|
|
|
842
|
-
|
|
843
|
-
|
|
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
|
-
|
|
846
|
-
|
|
847
|
-
|
|
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
|
-
|
|
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
|
}
|