react-native-beidou 1.1.4 → 1.1.7
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/Compass.android.tsx +4 -12
- package/Compass.ios.tsx +2 -3
- package/android/build.gradle +15 -2
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/fxzs.rnbeidou/BeiDouBluetoothModule.java +425 -185
- package/android/src/main/java/com/fxzs.rnbeidou/BeiDouBluetoothPackage.java +10 -13
- package/android/src/main/java/com/fxzs.rnbeidou/BeidouAidlHelper.java +45 -13
- package/android/src/main/java/com/fxzs.rnbeidou/SuperSimModule.java +301 -0
- package/android/src/main/java/com/fxzs.rnbeidou/view/CompassManager.java +15 -15
- package/android/src/main/java/com/fxzs.rnbeidou/view/CompassView.java +10 -4
- package/index.ts +100 -35
- package/ios/BeiDouBluetoothModule.m +147 -20
- 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/Info.plist +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeDirectory +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeRequirements +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeResources +11 -39
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeSignature +0 -0
- package/ios/CompassView.h +1 -0
- package/ios/CompassView.m +3 -0
- package/ios/CompassViewComponentView.h +11 -0
- package/ios/CompassViewComponentView.mm +64 -0
- package/package.json +3 -5
- package/react-native-beidou.podspec +2 -2
- package/src/CompassViewNativeComponent.ts +13 -0
- package/src/NativeBeiDouBluetooth.ts +57 -0
- package/src/NativeSuperSim.ts +21 -0
- package/BeiDouAIDLTestPage.tsx +0 -710
- package/LogManager.ts +0 -284
- package/TestPage.ts +0 -6
- package/android/.gradle/8.10/checksums/checksums.lock +0 -0
- package/android/.gradle/8.10/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.10/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.10/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.10/gc.properties +0 -0
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.9/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/config.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/AndroidProjectSystem.xml +0 -6
- package/android/.idea/caches/deviceStreaming.xml +0 -1306
- package/android/.idea/gradle.xml +0 -13
- package/android/.idea/migrations.xml +0 -10
- package/android/.idea/misc.xml +0 -9
- package/android/.idea/runConfigurations.xml +0 -17
- package/android/.idea/vcs.xml +0 -6
- package/android/local.properties +0 -8
- package/android/src/main/java/com/fxzs.rnbeidou/LogManager.java +0 -488
|
@@ -2,8 +2,10 @@ package com.fxzs.rnbeidou;
|
|
|
2
2
|
|
|
3
3
|
import android.Manifest;
|
|
4
4
|
import android.bluetooth.BluetoothAdapter;
|
|
5
|
+
import android.content.ContentResolver;
|
|
5
6
|
import android.content.Context;
|
|
6
7
|
import android.content.pm.PackageManager;
|
|
8
|
+
import android.database.Cursor;
|
|
7
9
|
import android.net.ConnectivityManager;
|
|
8
10
|
import android.net.NetworkInfo;
|
|
9
11
|
import android.net.wifi.WifiInfo;
|
|
@@ -13,6 +15,7 @@ import android.os.Build;
|
|
|
13
15
|
import android.os.Bundle;
|
|
14
16
|
import android.os.Handler;
|
|
15
17
|
import android.os.Looper;
|
|
18
|
+
import android.provider.ContactsContract;
|
|
16
19
|
import android.util.Log;
|
|
17
20
|
import android.location.Location;
|
|
18
21
|
import android.location.LocationListener;
|
|
@@ -52,26 +55,44 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
|
52
55
|
|
|
53
56
|
import org.json.JSONException;
|
|
54
57
|
|
|
58
|
+
import java.text.Collator;
|
|
55
59
|
import java.util.Arrays;
|
|
56
60
|
import java.util.Base64;
|
|
57
61
|
import java.util.LinkedList;
|
|
58
62
|
import java.util.Map;
|
|
59
63
|
import java.util.Objects;
|
|
60
64
|
import java.util.ArrayList;
|
|
65
|
+
import java.util.HashSet;
|
|
61
66
|
import java.util.List;
|
|
67
|
+
import java.util.Locale;
|
|
62
68
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
63
69
|
|
|
64
70
|
public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
71
|
+
public static final String NAME = "BeiDouBluetoothModule";
|
|
72
|
+
private static final String EVENT_BLUETOOTH_ERROR = "beidouBluetoothError";
|
|
73
|
+
private static final int RESULT_OK = 1;
|
|
74
|
+
private static final int RESULT_FAIL = 0;
|
|
75
|
+
private static final int RESULT_PERMISSION_DENIED = 3;
|
|
76
|
+
private static final int RESULT_BLUETOOTH_OFF = 4;
|
|
77
|
+
private static final int RESULT_LOCATION_OFF = 5;
|
|
78
|
+
private static final String[] PINYIN_BOUNDARY = {
|
|
79
|
+
"阿", "芭", "擦", "搭", "蛾", "发", "噶", "哈", "击", "喀", "垃",
|
|
80
|
+
"妈", "拿", "哦", "啪", "期", "然", "撒", "塌", "挖", "昔", "压", "匝"
|
|
81
|
+
};
|
|
82
|
+
private static final String[] PINYIN_INITIAL = {
|
|
83
|
+
"A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L",
|
|
84
|
+
"M", "N", "O", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"
|
|
85
|
+
};
|
|
65
86
|
private ReactContext reactContext;
|
|
66
|
-
private LogManager logger;
|
|
67
87
|
|
|
68
88
|
// 北斗AIDL服务辅助类
|
|
69
89
|
private final BeidouAidlHelper beidouAidlHelper;
|
|
90
|
+
private final AtomicBoolean sdkPushCallbackRegistered = new AtomicBoolean(false);
|
|
70
91
|
|
|
71
92
|
@NonNull
|
|
72
93
|
@Override
|
|
73
94
|
public String getName() {
|
|
74
|
-
return
|
|
95
|
+
return NAME;
|
|
75
96
|
}
|
|
76
97
|
|
|
77
98
|
public BeiDouBluetoothModule(@Nullable ReactApplicationContext reactContext) {
|
|
@@ -79,27 +100,107 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
79
100
|
this.reactContext = reactContext;
|
|
80
101
|
this.beidouAidlHelper = new BeidouAidlHelper(reactContext);
|
|
81
102
|
|
|
82
|
-
// 初始化日志管理器
|
|
83
|
-
this.logger = LogManager.getInstance();
|
|
84
|
-
// 默认配置:根据ApplicationInfo.FLAG_DEBUGGABLE判断是否为Debug模式
|
|
85
103
|
boolean isDebug = reactContext != null &&
|
|
86
104
|
(reactContext.getApplicationInfo().flags & android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
|
87
|
-
|
|
105
|
+
Log.i("BeiDouBluetoothModule", "BeiDouBluetoothModule initialized - Debug: " + isDebug);
|
|
106
|
+
}
|
|
88
107
|
|
|
89
|
-
|
|
108
|
+
private static final class BlePrereqResult {
|
|
109
|
+
final int code;
|
|
110
|
+
final String message;
|
|
90
111
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
112
|
+
BlePrereqResult(int code, String message) {
|
|
113
|
+
this.code = code;
|
|
114
|
+
this.message = message;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private void emitBluetoothError(int code, @Nullable String message) {
|
|
119
|
+
if (reactContext == null) return;
|
|
120
|
+
try {
|
|
121
|
+
WritableMap writableMap = new WritableNativeMap();
|
|
122
|
+
writableMap.putInt("code", code);
|
|
123
|
+
writableMap.putString("message", message == null ? "" : message);
|
|
124
|
+
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
125
|
+
.emit(EVENT_BLUETOOTH_ERROR, writableMap);
|
|
126
|
+
} catch (Throwable ignore) {
|
|
127
|
+
// 避免事件发送失败导致崩溃
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private BluetoothSDK getBluetoothSdkInitialized() {
|
|
132
|
+
BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
|
|
133
|
+
if (sdkPushCallbackRegistered.compareAndSet(false, true)) {
|
|
134
|
+
instance.setPushCallback(new BluetoothPushCallback() {
|
|
135
|
+
@Override
|
|
136
|
+
public void onDevicePush(String deviceNo, String data, int cmd) {
|
|
137
|
+
Log.d("BeiDouBluetoothModule", "收到设备推送消息: " + data);
|
|
138
|
+
ReactContext ctx = BeiDouBluetoothModule.this.reactContext;
|
|
139
|
+
if (ctx == null) return;
|
|
140
|
+
|
|
141
|
+
WritableMap writableMap = new WritableNativeMap();
|
|
142
|
+
writableMap.putInt("type", 0);
|
|
143
|
+
writableMap.putString("message", data);
|
|
144
|
+
ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
145
|
+
.emit("listenBluetoolth", writableMap);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return instance;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private boolean isLocationServiceEnabled() {
|
|
153
|
+
if (reactContext == null) return false;
|
|
154
|
+
try {
|
|
155
|
+
LocationManager locationManager = (LocationManager) reactContext.getSystemService(Context.LOCATION_SERVICE);
|
|
156
|
+
if (locationManager == null) return false;
|
|
157
|
+
|
|
158
|
+
boolean gpsEnabled = false;
|
|
159
|
+
boolean networkEnabled = false;
|
|
160
|
+
try {
|
|
161
|
+
gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
|
162
|
+
} catch (Exception ignore) {
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
|
166
|
+
} catch (Exception ignore) {
|
|
101
167
|
}
|
|
102
|
-
|
|
168
|
+
return gpsEnabled || networkEnabled;
|
|
169
|
+
} catch (Throwable ignore) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private BlePrereqResult checkBlePrerequisitesForScanOrConnect() {
|
|
175
|
+
if (reactContext == null) {
|
|
176
|
+
return new BlePrereqResult(RESULT_FAIL, "上下文为空,无法执行蓝牙操作");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
180
|
+
if (bluetoothAdapter == null) {
|
|
181
|
+
return new BlePrereqResult(RESULT_BLUETOOTH_OFF, "设备不支持蓝牙");
|
|
182
|
+
}
|
|
183
|
+
if (!bluetoothAdapter.isEnabled()) {
|
|
184
|
+
return new BlePrereqResult(RESULT_BLUETOOTH_OFF, "请先打开系统蓝牙开关");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
188
|
+
boolean scanGranted = ContextCompat.checkSelfPermission(reactContext, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED;
|
|
189
|
+
boolean connectGranted = ContextCompat.checkSelfPermission(reactContext, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED;
|
|
190
|
+
if (!scanGranted || !connectGranted) {
|
|
191
|
+
return new BlePrereqResult(RESULT_PERMISSION_DENIED, "缺少蓝牙权限,请在系统设置中允许“附近设备/蓝牙”权限");
|
|
192
|
+
}
|
|
193
|
+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
194
|
+
boolean locationGranted = ContextCompat.checkSelfPermission(reactContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
195
|
+
if (!locationGranted) {
|
|
196
|
+
return new BlePrereqResult(RESULT_PERMISSION_DENIED, "缺少定位权限(用于蓝牙扫描)");
|
|
197
|
+
}
|
|
198
|
+
if (!isLocationServiceEnabled()) {
|
|
199
|
+
return new BlePrereqResult(RESULT_LOCATION_OFF, "请先打开系统定位开关(用于蓝牙扫描)");
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return new BlePrereqResult(RESULT_OK, "");
|
|
103
204
|
}
|
|
104
205
|
|
|
105
206
|
// 消息数据库管理器实例
|
|
@@ -115,14 +216,14 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
115
216
|
|
|
116
217
|
// 插入北斗蓝牙短信
|
|
117
218
|
@ReactMethod
|
|
118
|
-
public void insertMsg(String phone, String content,
|
|
219
|
+
public void insertMsg(String phone, String content, double timestamp, boolean isSend) {
|
|
119
220
|
try {
|
|
120
|
-
long timeInterval =
|
|
121
|
-
boolean send = isSend
|
|
221
|
+
long timeInterval = (long) timestamp;
|
|
222
|
+
boolean send = isSend;
|
|
122
223
|
getChatDBManager().insertMessage(content, phone, send, timeInterval);
|
|
123
|
-
|
|
224
|
+
Log.d("BeiDouBluetoothModule", String.format("插入消息成功 - 手机号: %s, 是否发送: %b", phone, send));
|
|
124
225
|
} catch (Exception e) {
|
|
125
|
-
|
|
226
|
+
Log.e("BeiDouBluetoothModule", "插入消息失败: " + e.getMessage(), e);
|
|
126
227
|
}
|
|
127
228
|
}
|
|
128
229
|
|
|
@@ -141,10 +242,10 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
141
242
|
|
|
142
243
|
// 获取会话详情
|
|
143
244
|
@ReactMethod
|
|
144
|
-
public void getMessagesForPhone(String phone,
|
|
245
|
+
public void getMessagesForPhone(String phone, double page, double pageSize, Callback callback) {
|
|
145
246
|
try {
|
|
146
|
-
int pageNum =
|
|
147
|
-
int size =
|
|
247
|
+
int pageNum = (int) page;
|
|
248
|
+
int size = (int) pageSize;
|
|
148
249
|
|
|
149
250
|
List<Map<String, Object>> messages = getChatDBManager().getMessagesForPhone(phone, pageNum, size);
|
|
150
251
|
String jsonString = JsonUtil.objectToJson(messages);
|
|
@@ -159,50 +260,109 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
159
260
|
// 开始扫描蓝牙设备
|
|
160
261
|
@ReactMethod
|
|
161
262
|
public void startScanForService(Callback callback) {
|
|
162
|
-
|
|
263
|
+
// Android 12+ 理论上不强制依赖定位开关,但部分厂商机型仍会在定位关闭时扫不到设备
|
|
264
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !isLocationServiceEnabled()) {
|
|
265
|
+
emitBluetoothError(RESULT_LOCATION_OFF, "请先打开系统定位开关");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
BlePrereqResult prereq = checkBlePrerequisitesForScanOrConnect();
|
|
269
|
+
if (prereq.code != RESULT_OK) {
|
|
270
|
+
Log.w("BluetoothSDK", "startScanForService blocked: " + prereq.message);
|
|
271
|
+
emitBluetoothError(prereq.code, prereq.message);
|
|
272
|
+
if (callback != null) callback.invoke(prereq.code);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
BluetoothSDK instance = getBluetoothSdkInitialized();
|
|
163
276
|
Log.d("BluetoothSDK", "MyModule-> 开始扫描");
|
|
164
|
-
|
|
277
|
+
try {
|
|
278
|
+
instance.startScan();
|
|
279
|
+
if (callback != null) callback.invoke(RESULT_OK);
|
|
280
|
+
} catch (Throwable t) {
|
|
281
|
+
String msg = "开始扫描失败: " + (t.getMessage() == null ? t.getClass().getSimpleName() : t.getMessage());
|
|
282
|
+
Log.e("BluetoothSDK", msg, t);
|
|
283
|
+
emitBluetoothError(RESULT_FAIL, msg);
|
|
284
|
+
if (callback != null) callback.invoke(RESULT_FAIL);
|
|
285
|
+
}
|
|
165
286
|
}
|
|
166
287
|
|
|
167
288
|
// 停止扫描蓝牙设备
|
|
168
289
|
@ReactMethod
|
|
169
290
|
public void stopScanning() {
|
|
170
|
-
|
|
171
|
-
|
|
291
|
+
try {
|
|
292
|
+
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
293
|
+
if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) return;
|
|
294
|
+
BluetoothSDK instance = getBluetoothSdkInitialized();
|
|
295
|
+
instance.stopScan();
|
|
296
|
+
} catch (Throwable t) {
|
|
297
|
+
String msg = "停止扫描失败: " + (t.getMessage() == null ? t.getClass().getSimpleName() : t.getMessage());
|
|
298
|
+
Log.e("BluetoothSDK", msg, t);
|
|
299
|
+
emitBluetoothError(RESULT_FAIL, msg);
|
|
300
|
+
}
|
|
172
301
|
}
|
|
173
302
|
|
|
174
303
|
// 获取扫描结果
|
|
175
304
|
@ReactMethod
|
|
176
|
-
public void getDiscoveredDevices(Promise promise)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
305
|
+
public void getDiscoveredDevices(Promise promise) {
|
|
306
|
+
try {
|
|
307
|
+
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
308
|
+
if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
|
|
309
|
+
promise.resolve("[]");
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
BluetoothSDK instance = getBluetoothSdkInitialized();
|
|
313
|
+
Map<String, BlueDeviceInfoEntity> deviceInfoMap = instance.getScannedDevices();
|
|
314
|
+
|
|
315
|
+
// 将 BlueDeviceInfoEntity 对象转换为 List 以便序列化
|
|
316
|
+
List<BlueDeviceInfoEntity> deviceList = new ArrayList<>(deviceInfoMap.values());
|
|
317
|
+
String s = JsonUtil.objectToJson(deviceList);
|
|
318
|
+
Log.d("BluetoothSDK", "获取设备列表:" + s);
|
|
319
|
+
promise.resolve(s);
|
|
320
|
+
} catch (Throwable t) {
|
|
321
|
+
String msg = "获取设备列表失败: " + (t.getMessage() == null ? t.getClass().getSimpleName() : t.getMessage());
|
|
322
|
+
Log.e("BluetoothSDK", msg, t);
|
|
323
|
+
emitBluetoothError(RESULT_FAIL, msg);
|
|
324
|
+
promise.resolve("[]");
|
|
325
|
+
}
|
|
185
326
|
}
|
|
186
327
|
|
|
187
328
|
// 根据 deviceNo 连接蓝牙设备
|
|
188
329
|
@ReactMethod
|
|
189
|
-
public void connectToDeviceFromCloudDeviceNO(String deviceNO,
|
|
330
|
+
public void connectToDeviceFromCloudDeviceNO(String deviceNO, double a, Promise promise) {
|
|
190
331
|
if (StringUtils.isEmpty(deviceNO)) {
|
|
191
332
|
Log.e("BluetoothSDK", "connectToDeviceFromCloudDeviceNO: deviceNo isEmpty");
|
|
333
|
+
emitBluetoothError(RESULT_FAIL, "设备编号为空,无法连接");
|
|
192
334
|
promise.resolve("0");
|
|
193
335
|
return;
|
|
194
336
|
}
|
|
195
|
-
|
|
337
|
+
|
|
338
|
+
// Android 12+ 理论上不强制依赖定位开关,但部分厂商机型仍会在定位关闭时扫不到设备
|
|
339
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !isLocationServiceEnabled()) {
|
|
340
|
+
emitBluetoothError(RESULT_LOCATION_OFF, "请先打开系统定位开关(部分机型蓝牙扫描需要)");
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
BlePrereqResult prereq = checkBlePrerequisitesForScanOrConnect();
|
|
344
|
+
if (prereq.code != RESULT_OK) {
|
|
345
|
+
Log.w("BluetoothSDK", "connect blocked: " + prereq.message);
|
|
346
|
+
emitBluetoothError(prereq.code, prereq.message);
|
|
347
|
+
promise.resolve(String.valueOf(prereq.code));
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
BluetoothSDK instance = getBluetoothSdkInitialized();
|
|
352
|
+
AtomicBoolean handled = new AtomicBoolean(false);
|
|
196
353
|
BluetoothConnectionCallback connectionCallback = new BluetoothConnectionCallback() {
|
|
197
354
|
@Override
|
|
198
355
|
public void onConnected(String deviceNo) {
|
|
199
356
|
Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: 1");
|
|
357
|
+
if (handled.getAndSet(true)) return;
|
|
200
358
|
promise.resolve("1");
|
|
201
359
|
}
|
|
202
360
|
|
|
203
361
|
@Override
|
|
204
362
|
public void onConnectionFailed(String deviceNo, int errorCode, String errorMessage) {
|
|
205
363
|
Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: 0");
|
|
364
|
+
if (handled.getAndSet(true)) return;
|
|
365
|
+
emitBluetoothError(RESULT_FAIL, "连接失败: " + errorMessage);
|
|
206
366
|
promise.resolve("0");
|
|
207
367
|
}
|
|
208
368
|
|
|
@@ -210,6 +370,8 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
210
370
|
public void onDisconnected(String deviceNo) {
|
|
211
371
|
// 连接过程中意外断开
|
|
212
372
|
Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: 0");
|
|
373
|
+
if (handled.getAndSet(true)) return;
|
|
374
|
+
emitBluetoothError(RESULT_FAIL, "连接断开");
|
|
213
375
|
promise.resolve("0");
|
|
214
376
|
}
|
|
215
377
|
|
|
@@ -218,7 +380,15 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
218
380
|
// 服务发现完成,不需要特殊处理
|
|
219
381
|
}
|
|
220
382
|
};
|
|
221
|
-
|
|
383
|
+
try {
|
|
384
|
+
instance.connectDevice(deviceNO, connectionCallback);
|
|
385
|
+
} catch (Throwable t) {
|
|
386
|
+
if (handled.getAndSet(true)) return;
|
|
387
|
+
String msg = "发起连接异常: " + (t.getMessage() == null ? t.getClass().getSimpleName() : t.getMessage());
|
|
388
|
+
Log.e("BluetoothSDK", msg, t);
|
|
389
|
+
emitBluetoothError(RESULT_FAIL, msg);
|
|
390
|
+
promise.resolve("0");
|
|
391
|
+
}
|
|
222
392
|
}
|
|
223
393
|
|
|
224
394
|
/**
|
|
@@ -263,7 +433,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
263
433
|
* 蓝牙权限--根据Android的不同版本,判断是否具有蓝牙权限
|
|
264
434
|
*/
|
|
265
435
|
@ReactMethod
|
|
266
|
-
public void checkBlueToothPermission(Callback callback)
|
|
436
|
+
public void checkBlueToothPermission(Callback callback) {
|
|
267
437
|
if (reactContext == null) {
|
|
268
438
|
return;
|
|
269
439
|
}
|
|
@@ -306,7 +476,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
306
476
|
* 蓝牙权限--BLUETOOTH
|
|
307
477
|
*/
|
|
308
478
|
@ReactMethod
|
|
309
|
-
public void shouldShowBlueToothPermissionRationale(String params, Callback callback)
|
|
479
|
+
public void shouldShowBlueToothPermissionRationale(String params, Callback callback) {
|
|
310
480
|
String ret = "";
|
|
311
481
|
System.out.println("获取Android版本2::::::::::::::Build.VERSION.SDK_INT" + Build.VERSION.SDK_INT);
|
|
312
482
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
@@ -335,7 +505,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
335
505
|
* 初始化蓝牙--BLUETOOTH
|
|
336
506
|
*/
|
|
337
507
|
@ReactMethod
|
|
338
|
-
public void initializeBluetooth(Callback callback)
|
|
508
|
+
public void initializeBluetooth(Callback callback) {
|
|
339
509
|
String ret = "";
|
|
340
510
|
System.out.println("初始化蓝牙操作::::::::::::::Build.VERSION.SDK_INT" + Build.VERSION.SDK_INT);
|
|
341
511
|
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
@@ -363,8 +533,8 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
363
533
|
public String generateRandom16BytesString() {
|
|
364
534
|
byte[] bytes = ByteUtil.generateRandomHexBytes(32);
|
|
365
535
|
Log.d("BluetoothSDK", "获取随机字节数组:" + Arrays.toString(bytes));
|
|
366
|
-
|
|
367
|
-
String b = "2PJFUoUNB502/KJdVQg5Kg==";
|
|
536
|
+
String b = java.util.Base64.getEncoder().encodeToString(bytes);
|
|
537
|
+
// String b = "2PJFUoUNB502/KJdVQg5Kg==";
|
|
368
538
|
Log.d("BluetoothSDK", "随机字节数组加密 Base64字符串:" + b);
|
|
369
539
|
return b;
|
|
370
540
|
}
|
|
@@ -380,7 +550,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
380
550
|
// instance.writeData(randomString, deviceNo, command, attrType,true,callback);
|
|
381
551
|
// }
|
|
382
552
|
@ReactMethod
|
|
383
|
-
public void writeData(String randomString, String deviceNo,
|
|
553
|
+
public void writeData(String randomString, String deviceNo, double command, double attrType,
|
|
384
554
|
Callback writeCallback) {
|
|
385
555
|
BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
|
|
386
556
|
Log.d("BluetoothSDK", "收到写入请求" + command + " " + attrType + " " + randomString);
|
|
@@ -420,15 +590,15 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
420
590
|
}
|
|
421
591
|
};
|
|
422
592
|
instance.setDataCallback(dataCallback);
|
|
423
|
-
instance.writeData(randomString, deviceNo, command, attrType);
|
|
593
|
+
instance.writeData(randomString, deviceNo, (int) command, (int) attrType);
|
|
424
594
|
}
|
|
425
595
|
|
|
426
596
|
// 存储BLE密钥的字段
|
|
427
597
|
private String bleKeyHex = "";
|
|
428
598
|
|
|
429
599
|
@ReactMethod
|
|
430
|
-
public void writeInfo(@Nullable String base64Payload, String deviceNO,
|
|
431
|
-
|
|
600
|
+
public void writeInfo(@Nullable String base64Payload, String deviceNO, double command, double opCode,
|
|
601
|
+
double attrType, boolean encrypted, Promise promise) {
|
|
432
602
|
try {
|
|
433
603
|
BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
|
|
434
604
|
|
|
@@ -448,10 +618,10 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
448
618
|
}
|
|
449
619
|
|
|
450
620
|
// 转换参数类型
|
|
451
|
-
int commandValue = command
|
|
452
|
-
int opCodeValue = opCode
|
|
453
|
-
int attrTypeValue = attrType
|
|
454
|
-
boolean isEncrypted = encrypted
|
|
621
|
+
int commandValue = (int) command;
|
|
622
|
+
int opCodeValue = (int) opCode;
|
|
623
|
+
int attrTypeValue = (int) attrType;
|
|
624
|
+
boolean isEncrypted = encrypted;
|
|
455
625
|
|
|
456
626
|
Log.d("BluetoothSDK", String.format(
|
|
457
627
|
"writeInfo - deviceNO: %s, command: 0x%02X, opCode: 0x%02X, attrType: 0x%04X, encrypted: %b",
|
|
@@ -511,7 +681,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
511
681
|
}
|
|
512
682
|
|
|
513
683
|
@ReactMethod
|
|
514
|
-
public void writeValueInfo(String randomString, String deviceNo,
|
|
684
|
+
public void writeValueInfo(String randomString, String deviceNo, double command, double attrType, double value,
|
|
515
685
|
Callback writeCallback) {
|
|
516
686
|
// BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
|
|
517
687
|
// Log.d(BluetoothSDK.TAG, "收到写入请求" + command +" "+attrType+" "+randomString);
|
|
@@ -757,11 +927,173 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
757
927
|
promise.reject("PERMISSION_DENIED", "获取SIM卡信息权限被拒绝: " + permissionException.getMessage(),
|
|
758
928
|
permissionException);
|
|
759
929
|
} catch (Exception e) {
|
|
760
|
-
|
|
930
|
+
Log.e("BeiDouBluetoothModule", "获取SIM卡信息失败: " + e.getMessage(), e);
|
|
761
931
|
promise.reject("SIM_INFO_ERROR", "获取SIM卡信息失败: " + e.getMessage(), e);
|
|
762
932
|
}
|
|
763
933
|
}
|
|
764
934
|
|
|
935
|
+
/**
|
|
936
|
+
* 获取系统通讯录(仅返回包含号码的联系人)
|
|
937
|
+
* 返回结构:
|
|
938
|
+
* [
|
|
939
|
+
* {
|
|
940
|
+
* "id": "123",
|
|
941
|
+
* "name": "张三",
|
|
942
|
+
* "firstLetter": "Z",
|
|
943
|
+
* "phoneNumbers": ["13800138000", ...]
|
|
944
|
+
* }
|
|
945
|
+
* ]
|
|
946
|
+
*/
|
|
947
|
+
@ReactMethod
|
|
948
|
+
public void getContacts(Promise promise) {
|
|
949
|
+
try {
|
|
950
|
+
if (reactContext == null) {
|
|
951
|
+
promise.reject("CONTEXT_NULL", "React上下文不可用");
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
Context context = reactContext.getCurrentActivity();
|
|
956
|
+
if (context == null) {
|
|
957
|
+
context = reactContext;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS)
|
|
961
|
+
!= PackageManager.PERMISSION_GRANTED) {
|
|
962
|
+
promise.reject("PERMISSION_DENIED", "缺少通讯录权限: READ_CONTACTS");
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
ContentResolver contentResolver = context.getContentResolver();
|
|
967
|
+
WritableArray contactsArray = new WritableNativeArray();
|
|
968
|
+
|
|
969
|
+
Cursor contactsCursor = null;
|
|
970
|
+
try {
|
|
971
|
+
contactsCursor = contentResolver.query(
|
|
972
|
+
ContactsContract.Contacts.CONTENT_URI,
|
|
973
|
+
new String[] {
|
|
974
|
+
ContactsContract.Contacts._ID,
|
|
975
|
+
ContactsContract.Contacts.DISPLAY_NAME,
|
|
976
|
+
ContactsContract.Contacts.HAS_PHONE_NUMBER
|
|
977
|
+
},
|
|
978
|
+
null,
|
|
979
|
+
null,
|
|
980
|
+
ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
|
|
981
|
+
|
|
982
|
+
if (contactsCursor == null) {
|
|
983
|
+
promise.resolve(contactsArray);
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
int idIndex = contactsCursor.getColumnIndex(ContactsContract.Contacts._ID);
|
|
988
|
+
int nameIndex = contactsCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
|
|
989
|
+
int hasPhoneIndex = contactsCursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);
|
|
990
|
+
|
|
991
|
+
while (contactsCursor.moveToNext()) {
|
|
992
|
+
if (idIndex < 0 || nameIndex < 0 || hasPhoneIndex < 0) {
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
String contactId = contactsCursor.getString(idIndex);
|
|
997
|
+
String displayName = contactsCursor.getString(nameIndex);
|
|
998
|
+
int hasPhoneNumber = contactsCursor.getInt(hasPhoneIndex);
|
|
999
|
+
if (hasPhoneNumber <= 0) {
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
WritableArray phoneNumbers = new WritableNativeArray();
|
|
1004
|
+
HashSet<String> dedup = new HashSet<>();
|
|
1005
|
+
Cursor phonesCursor = null;
|
|
1006
|
+
try {
|
|
1007
|
+
phonesCursor = contentResolver.query(
|
|
1008
|
+
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
|
1009
|
+
new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER },
|
|
1010
|
+
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=?",
|
|
1011
|
+
new String[] { contactId },
|
|
1012
|
+
null);
|
|
1013
|
+
|
|
1014
|
+
if (phonesCursor != null) {
|
|
1015
|
+
int numberIndex =
|
|
1016
|
+
phonesCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
|
|
1017
|
+
while (phonesCursor.moveToNext()) {
|
|
1018
|
+
if (numberIndex < 0) {
|
|
1019
|
+
continue;
|
|
1020
|
+
}
|
|
1021
|
+
String rawNumber = phonesCursor.getString(numberIndex);
|
|
1022
|
+
if (rawNumber == null || rawNumber.trim().isEmpty()) {
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
String cleaned = rawNumber.replaceAll("\\D", "");
|
|
1026
|
+
if (cleaned.isEmpty() || dedup.contains(cleaned)) {
|
|
1027
|
+
continue;
|
|
1028
|
+
}
|
|
1029
|
+
dedup.add(cleaned);
|
|
1030
|
+
phoneNumbers.pushString(cleaned);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
} finally {
|
|
1034
|
+
if (phonesCursor != null) {
|
|
1035
|
+
phonesCursor.close();
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
if (phoneNumbers.size() == 0) {
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
String name = (displayName == null || displayName.trim().isEmpty())
|
|
1044
|
+
? "未知联系人"
|
|
1045
|
+
: displayName.trim();
|
|
1046
|
+
|
|
1047
|
+
String firstLetter = getSortLetter(name);
|
|
1048
|
+
|
|
1049
|
+
WritableMap contact = new WritableNativeMap();
|
|
1050
|
+
contact.putString("id", contactId);
|
|
1051
|
+
contact.putString("name", name);
|
|
1052
|
+
contact.putString("firstLetter", firstLetter);
|
|
1053
|
+
contact.putArray("phoneNumbers", phoneNumbers);
|
|
1054
|
+
contactsArray.pushMap(contact);
|
|
1055
|
+
}
|
|
1056
|
+
} finally {
|
|
1057
|
+
if (contactsCursor != null) {
|
|
1058
|
+
contactsCursor.close();
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
promise.resolve(contactsArray);
|
|
1063
|
+
} catch (SecurityException permissionException) {
|
|
1064
|
+
promise.reject("PERMISSION_DENIED", "读取通讯录权限被拒绝: " + permissionException.getMessage(),
|
|
1065
|
+
permissionException);
|
|
1066
|
+
} catch (Exception e) {
|
|
1067
|
+
Log.e("BeiDouBluetoothModule", "获取通讯录失败: " + e.getMessage(), e);
|
|
1068
|
+
promise.reject("CONTACTS_ERROR", "获取通讯录失败: " + e.getMessage(), e);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* 联系人分组首字母:
|
|
1074
|
+
* - 英文开头:直接取 A-Z
|
|
1075
|
+
* - 汉字开头:按拼音首字母归组
|
|
1076
|
+
* - 其它:#
|
|
1077
|
+
*/
|
|
1078
|
+
private String getSortLetter(String name) {
|
|
1079
|
+
if (name == null || name.trim().isEmpty()) {
|
|
1080
|
+
return "#";
|
|
1081
|
+
}
|
|
1082
|
+
String firstChar = name.trim().substring(0, 1);
|
|
1083
|
+
String upper = firstChar.toUpperCase(Locale.ROOT);
|
|
1084
|
+
if (upper.matches("[A-Z]")) {
|
|
1085
|
+
return upper;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
Collator collator = Collator.getInstance(Locale.CHINA);
|
|
1089
|
+
for (int i = PINYIN_BOUNDARY.length - 1; i >= 0; i--) {
|
|
1090
|
+
if (collator.compare(firstChar, PINYIN_BOUNDARY[i]) >= 0) {
|
|
1091
|
+
return PINYIN_INITIAL[i];
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return "#";
|
|
1095
|
+
}
|
|
1096
|
+
|
|
765
1097
|
// ================== 北斗AIDL服务相关方法 ==================
|
|
766
1098
|
|
|
767
1099
|
@ReactMethod
|
|
@@ -775,8 +1107,8 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
775
1107
|
}
|
|
776
1108
|
|
|
777
1109
|
@ReactMethod
|
|
778
|
-
public void BDAuthenticate(
|
|
779
|
-
beidouAidlHelper.authenticate(slotId, promise);
|
|
1110
|
+
public void BDAuthenticate(double slotId, Promise promise) {
|
|
1111
|
+
beidouAidlHelper.authenticate((int) slotId, promise);
|
|
780
1112
|
// new Thread(() -> {
|
|
781
1113
|
// BDMsgGetKeyAndAuthTerminalResponse ksKeyAndAuthResult = BDMsgAuthTerminalSdk.getInstance(reactContext).getKsKeyAndAuthResult(slotId);
|
|
782
1114
|
// promise.resolve(ksKeyAndAuthResult.toString());
|
|
@@ -784,8 +1116,8 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
784
1116
|
}
|
|
785
1117
|
|
|
786
1118
|
@ReactMethod
|
|
787
|
-
public void getBDMsgStatus(
|
|
788
|
-
beidouAidlHelper.getStatus(slotId, promise);
|
|
1119
|
+
public void getBDMsgStatus(double slotId, Promise promise) {
|
|
1120
|
+
beidouAidlHelper.getStatus((int) slotId, promise);
|
|
789
1121
|
// new Thread(() -> {
|
|
790
1122
|
// BDMsgGetUserInfoTerminalResponse currentUserInfo = BDMsgAuthTerminalSdk.getInstance(reactContext).getCurrentUserInfo(slotId);
|
|
791
1123
|
// promise.resolve(currentUserInfo.toString());
|
|
@@ -793,8 +1125,8 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
793
1125
|
}
|
|
794
1126
|
|
|
795
1127
|
@ReactMethod
|
|
796
|
-
public void checkValidatedKey(
|
|
797
|
-
beidouAidlHelper.checkValidatedKey(slotId, promise);
|
|
1128
|
+
public void checkValidatedKey(double slotId, Promise promise) {
|
|
1129
|
+
beidouAidlHelper.checkValidatedKey((int) slotId, promise);
|
|
798
1130
|
// new Thread(() -> {
|
|
799
1131
|
// int i = BDMsgAuthTerminalSdk.getInstance(reactContext).checkKeyIsExistAndValidate(slotId);
|
|
800
1132
|
// promise.resolve(i);
|
|
@@ -802,9 +1134,9 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
802
1134
|
}
|
|
803
1135
|
|
|
804
1136
|
@ReactMethod
|
|
805
|
-
public void commonBDMsgEncrypt(
|
|
1137
|
+
public void commonBDMsgEncrypt(double slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
|
|
806
1138
|
Promise promise) {
|
|
807
|
-
beidouAidlHelper.commonBDMsgEncrypt(slotId, speedType, receiveList, inputMsg, promise);
|
|
1139
|
+
beidouAidlHelper.commonBDMsgEncrypt((int) slotId, speedType, receiveList, inputMsg, promise);
|
|
808
1140
|
// new Thread(() -> {
|
|
809
1141
|
// LinkedList<String> receiveStringList = readableArrayToStringList(receiveList);
|
|
810
1142
|
// List<BDMsgSMCryptResponse> bdMsgSMCryptResponses = BDMsgAuthTerminalSdk.getInstance(reactContext).commonMessageEncryptBDMsgByTerminal(slotId, speedType, receiveStringList, inputMsg);
|
|
@@ -813,9 +1145,9 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
813
1145
|
}
|
|
814
1146
|
|
|
815
1147
|
@ReactMethod
|
|
816
|
-
public void positionBDMsgEncrypt(
|
|
1148
|
+
public void positionBDMsgEncrypt(double slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
|
|
817
1149
|
double longitude, double latitude, Promise promise) {
|
|
818
|
-
beidouAidlHelper.positionBDMsgEncrypt(slotId, speedType, receiveList, inputMsg, longitude, latitude, promise);
|
|
1150
|
+
beidouAidlHelper.positionBDMsgEncrypt((int) slotId, speedType, receiveList, inputMsg, longitude, latitude, promise);
|
|
819
1151
|
// new Thread(() -> {
|
|
820
1152
|
// LinkedList<String> receiveStringList = readableArrayToStringList(receiveList);
|
|
821
1153
|
// List<BDMsgSMCryptResponse> bdMsgSMCryptResponses = BDMsgAuthTerminalSdk.getInstance(reactContext).positionReportEncryptBDMsgByTerminal(slotId, speedType, receiveStringList, inputMsg, longitude, latitude);
|
|
@@ -824,9 +1156,9 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
824
1156
|
}
|
|
825
1157
|
|
|
826
1158
|
@ReactMethod
|
|
827
|
-
public void commonEmergencyBDMsgEncrypt(
|
|
1159
|
+
public void commonEmergencyBDMsgEncrypt(double slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
|
|
828
1160
|
Promise promise) {
|
|
829
|
-
beidouAidlHelper.commonEmergencyBDMsgEncrypt(slotId, speedType, receiveList, inputMsg, promise);
|
|
1161
|
+
beidouAidlHelper.commonEmergencyBDMsgEncrypt((int) slotId, speedType, receiveList, inputMsg, promise);
|
|
830
1162
|
// new Thread(() -> {
|
|
831
1163
|
// LinkedList<String> receiveStringList = readableArrayToStringList(receiveList);
|
|
832
1164
|
// List<BDMsgSMCryptResponse> bdMsgSMCryptResponses = BDMsgAuthTerminalSdk.getInstance(reactContext).commonMessageEncryptBDMsgByEmergencyTerminal(slotId, speedType, receiveStringList, inputMsg);
|
|
@@ -835,9 +1167,9 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
835
1167
|
}
|
|
836
1168
|
|
|
837
1169
|
@ReactMethod
|
|
838
|
-
public void positionEmergencyBDMsgEncrypt(
|
|
1170
|
+
public void positionEmergencyBDMsgEncrypt(double slotId, String speedType, @Nullable ReadableArray receiveList, String inputMsg,
|
|
839
1171
|
double longitude, double latitude, Promise promise) {
|
|
840
|
-
beidouAidlHelper.positionEmergencyBDMsgEncrypt(slotId, speedType, receiveList, inputMsg, longitude, latitude, promise);
|
|
1172
|
+
beidouAidlHelper.positionEmergencyBDMsgEncrypt((int) slotId, speedType, receiveList, inputMsg, longitude, latitude, promise);
|
|
841
1173
|
// new Thread(() -> {
|
|
842
1174
|
// LinkedList<String> receiveStringList = readableArrayToStringList(receiveList);
|
|
843
1175
|
// List<BDMsgSMCryptResponse> bdMsgSMCryptResponses = BDMsgAuthTerminalSdk.getInstance(reactContext).positionReportEncryptBDMsgByEmergencyTerminal(slotId, speedType, receiveStringList, inputMsg, longitude, latitude);
|
|
@@ -846,9 +1178,9 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
846
1178
|
}
|
|
847
1179
|
|
|
848
1180
|
@ReactMethod
|
|
849
|
-
public void commonRichMediaBDMsgEncrypt(
|
|
1181
|
+
public void commonRichMediaBDMsgEncrypt(double slotId, String speedType, @Nullable ReadableArray receiveList, String msgType,
|
|
850
1182
|
@Nullable ReadableArray inputRichMediaData, Promise promise) {
|
|
851
|
-
beidouAidlHelper.commonRichMediaBDMsgEncrypt(slotId, speedType, receiveList, msgType, inputRichMediaData, promise);
|
|
1183
|
+
beidouAidlHelper.commonRichMediaBDMsgEncrypt((int) slotId, speedType, receiveList, msgType, inputRichMediaData, promise);
|
|
852
1184
|
// new Thread(() -> {
|
|
853
1185
|
// LinkedList<String> receiveStringList = readableArrayToStringList(receiveList);
|
|
854
1186
|
// byte[] bytes = readableArrayToByteArray(inputRichMediaData);
|
|
@@ -858,9 +1190,9 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
858
1190
|
}
|
|
859
1191
|
|
|
860
1192
|
@ReactMethod
|
|
861
|
-
public void positionRichMediaBDMsgEncrypt(
|
|
1193
|
+
public void positionRichMediaBDMsgEncrypt(double slotId, String speedType, @Nullable ReadableArray receiveList, String msgType,
|
|
862
1194
|
@Nullable ReadableArray inputRichMediaData, double longitude, double latitude, Promise promise) {
|
|
863
|
-
beidouAidlHelper.positionRichMediaBDMsgEncrypt(slotId, speedType, receiveList, msgType, inputRichMediaData, longitude,
|
|
1195
|
+
beidouAidlHelper.positionRichMediaBDMsgEncrypt((int) slotId, speedType, receiveList, msgType, inputRichMediaData, longitude,
|
|
864
1196
|
latitude, promise);
|
|
865
1197
|
// new Thread(() -> {
|
|
866
1198
|
// LinkedList<String> receiveStringList = readableArrayToStringList(receiveList);
|
|
@@ -871,9 +1203,9 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
871
1203
|
}
|
|
872
1204
|
|
|
873
1205
|
@ReactMethod
|
|
874
|
-
public void commonRichMediaAndTextBDMsgEncrypt(
|
|
1206
|
+
public void commonRichMediaAndTextBDMsgEncrypt(double slotId, String speedType, @Nullable ReadableArray receiveList, String text,
|
|
875
1207
|
String msgType, @Nullable ReadableArray inputRichMediaData, Promise promise) {
|
|
876
|
-
beidouAidlHelper.commonRichMediaAndTextBDMsgEncrypt(slotId, speedType, receiveList, text, msgType, inputRichMediaData,
|
|
1208
|
+
beidouAidlHelper.commonRichMediaAndTextBDMsgEncrypt((int) slotId, speedType, receiveList, text, msgType, inputRichMediaData,
|
|
877
1209
|
promise);
|
|
878
1210
|
// new Thread(() -> {
|
|
879
1211
|
// LinkedList<String> receiveStringList = readableArrayToStringList(receiveList);
|
|
@@ -884,9 +1216,9 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
884
1216
|
}
|
|
885
1217
|
|
|
886
1218
|
@ReactMethod
|
|
887
|
-
public void positionRichMediaAndTextBDMsgEncrypt(
|
|
1219
|
+
public void positionRichMediaAndTextBDMsgEncrypt(double slotId, String speedType, @Nullable ReadableArray receiveList, String text,
|
|
888
1220
|
String msgType, @Nullable ReadableArray inputRichMediaData, double longitude, double latitude, Promise promise) {
|
|
889
|
-
beidouAidlHelper.positionRichMediaAndTextBDMsgEncrypt(slotId, speedType, receiveList, text, msgType, inputRichMediaData,
|
|
1221
|
+
beidouAidlHelper.positionRichMediaAndTextBDMsgEncrypt((int) slotId, speedType, receiveList, text, msgType, inputRichMediaData,
|
|
890
1222
|
longitude, latitude, promise);
|
|
891
1223
|
// new Thread(() -> {
|
|
892
1224
|
// LinkedList<String> receiveStringList = readableArrayToStringList(receiveList);
|
|
@@ -897,8 +1229,8 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
897
1229
|
}
|
|
898
1230
|
|
|
899
1231
|
@ReactMethod
|
|
900
|
-
public void BDMailboxQueryEncrypt(
|
|
901
|
-
beidouAidlHelper.mailboxQueryEncrypt(slotId, promise);
|
|
1232
|
+
public void BDMailboxQueryEncrypt(double slotId, Promise promise) {
|
|
1233
|
+
beidouAidlHelper.mailboxQueryEncrypt((int) slotId, promise);
|
|
902
1234
|
// new Thread(() -> {
|
|
903
1235
|
// BDMsgSMCryptResponse bdMsgSMCryptResponse = BDMsgAuthTerminalSdk.getInstance(reactContext).mailboxQueryEncryptBDMsg(slotId);
|
|
904
1236
|
// promise.resolve(bdMsgSMCryptResponse.toString());
|
|
@@ -906,8 +1238,8 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
906
1238
|
}
|
|
907
1239
|
|
|
908
1240
|
@ReactMethod
|
|
909
|
-
public void EmergencyBDMailboxQueryEncrypt(
|
|
910
|
-
beidouAidlHelper.emergencyMailboxQueryEncrypt(slotId, replyMobile, promise);
|
|
1241
|
+
public void EmergencyBDMailboxQueryEncrypt(double slotId, String replyMobile, Promise promise) {
|
|
1242
|
+
beidouAidlHelper.emergencyMailboxQueryEncrypt((int) slotId, replyMobile, promise);
|
|
911
1243
|
// new Thread(() -> {
|
|
912
1244
|
// BDMsgSMCryptResponse bdMsgSMCryptResponse = BDMsgAuthTerminalSdk.getInstance(reactContext).mailboxQueryEncryptBDMsgByEmergency(slotId,replyMobile);
|
|
913
1245
|
// promise.resolve(bdMsgSMCryptResponse.toString());
|
|
@@ -915,8 +1247,8 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
915
1247
|
}
|
|
916
1248
|
|
|
917
1249
|
@ReactMethod
|
|
918
|
-
public void BDMsgDecrypt(
|
|
919
|
-
beidouAidlHelper.decryptMessage(slotId, msg, len, promise);
|
|
1250
|
+
public void BDMsgDecrypt(double slotId, @Nullable ReadableArray msg, double len, Promise promise) {
|
|
1251
|
+
beidouAidlHelper.decryptMessage((int) slotId, msg, (int) len, promise);
|
|
920
1252
|
// new Thread(() -> {
|
|
921
1253
|
// byte[] bytes = readableArrayToByteArray(msg);
|
|
922
1254
|
// BDMsgMailReplyResponse bdMsgMailReplyResponse = BDMsgAuthTerminalSdk.getInstance(reactContext).mailboxReplyDecryptBDMsg(slotId, bytes, len);
|
|
@@ -925,8 +1257,8 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
925
1257
|
}
|
|
926
1258
|
|
|
927
1259
|
@ReactMethod
|
|
928
|
-
public void DLEphemerisFile(
|
|
929
|
-
beidouAidlHelper.downloadEphemerisFile(slotId, type, version, promise);
|
|
1260
|
+
public void DLEphemerisFile(double slotId, String type, String version, Promise promise) {
|
|
1261
|
+
beidouAidlHelper.downloadEphemerisFile((int) slotId, type, version, promise);
|
|
930
1262
|
// new Thread(() -> {
|
|
931
1263
|
// BDMsgEphemerisFileDownloadResponse bdMsgEphemerisFileDownloadResponse = BDMsgAuthTerminalSdk.getInstance(reactContext).downloadEphemerisFile(slotId, type, version);
|
|
932
1264
|
// promise.resolve(bdMsgEphemerisFileDownloadResponse.toString());
|
|
@@ -1021,7 +1353,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
1021
1353
|
});
|
|
1022
1354
|
|
|
1023
1355
|
} catch (Exception e) {
|
|
1024
|
-
|
|
1356
|
+
Log.e("BeiDouBluetoothModule", "获取GPS位置失败: " + e.getMessage(), e);
|
|
1025
1357
|
promise.reject("LOCATION_ERROR", "获取GPS位置失败: " + e.getMessage(), e);
|
|
1026
1358
|
}
|
|
1027
1359
|
}
|
|
@@ -1132,107 +1464,15 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
1132
1464
|
}
|
|
1133
1465
|
}
|
|
1134
1466
|
|
|
1135
|
-
//
|
|
1467
|
+
// SDK logging uses android.util.Log directly now.
|
|
1136
1468
|
|
|
1137
|
-
/**
|
|
1138
|
-
* 配置日志管理器
|
|
1139
|
-
*
|
|
1140
|
-
* @param enableFileLog 是否启用文件日志
|
|
1141
|
-
* @param enableConsoleLog 是否启用控制台日志
|
|
1142
|
-
* @param maxFileSize 最大文件大小(MB)
|
|
1143
|
-
* @param maxFileCount 最大文件数量
|
|
1144
|
-
* @param encryptionKey 加密密钥(可选)
|
|
1145
|
-
*/
|
|
1146
1469
|
@ReactMethod
|
|
1147
|
-
public void
|
|
1148
|
-
|
|
1149
|
-
@Nullable String encryptionKey, Promise promise) {
|
|
1150
|
-
try {
|
|
1151
|
-
// 重新初始化日志管理器
|
|
1152
|
-
boolean isDebug = reactContext != null &&
|
|
1153
|
-
(reactContext.getApplicationInfo().flags & android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
|
1154
|
-
|
|
1155
|
-
logger.initialize(reactContext, isDebug, enableFileLog, encryptionKey);
|
|
1156
|
-
logger.setLogConfig(enableFileLog, enableConsoleLog,
|
|
1157
|
-
(long) (maxFileSize * 1024 * 1024), maxFileCount);
|
|
1158
|
-
|
|
1159
|
-
logger.i("BeiDouBluetoothModule", "Logger configured - FileLog: " + enableFileLog +
|
|
1160
|
-
", ConsoleLog: " + enableConsoleLog +
|
|
1161
|
-
", MaxFileSize: " + maxFileSize + "MB" +
|
|
1162
|
-
", MaxFileCount: " + maxFileCount +
|
|
1163
|
-
", Encryption: " + (encryptionKey != null));
|
|
1164
|
-
|
|
1165
|
-
promise.resolve(true);
|
|
1166
|
-
} catch (Exception e) {
|
|
1167
|
-
logger.e("BeiDouBluetoothModule", "配置日志管理器失败: " + e.getMessage(), e);
|
|
1168
|
-
promise.reject("CONFIG_ERROR", "配置日志管理器失败: " + e.getMessage(), e);
|
|
1169
|
-
}
|
|
1470
|
+
public void addListener(String eventName) {
|
|
1471
|
+
// Required for RN 0.65+ to avoid warnings when JS adds listeners.
|
|
1170
1472
|
}
|
|
1171
1473
|
|
|
1172
|
-
/**
|
|
1173
|
-
* 获取日志统计信息
|
|
1174
|
-
*/
|
|
1175
1474
|
@ReactMethod
|
|
1176
|
-
public void
|
|
1177
|
-
|
|
1178
|
-
String stats = logger.getLogStats();
|
|
1179
|
-
promise.resolve(stats);
|
|
1180
|
-
} catch (Exception e) {
|
|
1181
|
-
logger.e("BeiDouBluetoothModule", "获取日志统计失败: " + e.getMessage(), e);
|
|
1182
|
-
promise.reject("STATS_ERROR", "获取日志统计失败: " + e.getMessage(), e);
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
/**
|
|
1187
|
-
* 清空所有日志文件
|
|
1188
|
-
*/
|
|
1189
|
-
@ReactMethod
|
|
1190
|
-
public void clearAllLogs(Promise promise) {
|
|
1191
|
-
try {
|
|
1192
|
-
logger.clearAllLogs();
|
|
1193
|
-
logger.i("BeiDouBluetoothModule", "所有日志文件已清空");
|
|
1194
|
-
promise.resolve(true);
|
|
1195
|
-
} catch (Exception e) {
|
|
1196
|
-
logger.e("BeiDouBluetoothModule", "清空日志失败: " + e.getMessage(), e);
|
|
1197
|
-
promise.reject("CLEAR_ERROR", "清空日志失败: " + e.getMessage(), e);
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
/**
|
|
1202
|
-
* 手动记录日志
|
|
1203
|
-
*/
|
|
1204
|
-
@ReactMethod
|
|
1205
|
-
public void writeLog(String level, String tag, String message, Promise promise) {
|
|
1206
|
-
try {
|
|
1207
|
-
switch (level.toUpperCase()) {
|
|
1208
|
-
case "VERBOSE":
|
|
1209
|
-
case "V":
|
|
1210
|
-
logger.v(tag, message);
|
|
1211
|
-
break;
|
|
1212
|
-
case "DEBUG":
|
|
1213
|
-
case "D":
|
|
1214
|
-
logger.d(tag, message);
|
|
1215
|
-
break;
|
|
1216
|
-
case "INFO":
|
|
1217
|
-
case "I":
|
|
1218
|
-
logger.i(tag, message);
|
|
1219
|
-
break;
|
|
1220
|
-
case "WARN":
|
|
1221
|
-
case "W":
|
|
1222
|
-
logger.w(tag, message);
|
|
1223
|
-
break;
|
|
1224
|
-
case "ERROR":
|
|
1225
|
-
case "E":
|
|
1226
|
-
logger.e(tag, message);
|
|
1227
|
-
break;
|
|
1228
|
-
default:
|
|
1229
|
-
logger.i(tag, message);
|
|
1230
|
-
break;
|
|
1231
|
-
}
|
|
1232
|
-
promise.resolve(true);
|
|
1233
|
-
} catch (Exception e) {
|
|
1234
|
-
logger.e("BeiDouBluetoothModule", "写入日志失败: " + e.getMessage(), e);
|
|
1235
|
-
promise.reject("LOG_ERROR", "写入日志失败: " + e.getMessage(), e);
|
|
1236
|
-
}
|
|
1475
|
+
public void removeListeners(double count) {
|
|
1476
|
+
// Required for RN 0.65+ to avoid warnings when JS removes listeners.
|
|
1237
1477
|
}
|
|
1238
1478
|
}
|