Browse Source

优化 配对名校验

newdev_chengguofeng
liwei1dao 3 months ago
parent
commit
8d6ebc8ffe
  1. 20
      lib/modules/pairing/controllers/pairing_controller.dart

20
lib/modules/pairing/controllers/pairing_controller.dart

@ -788,17 +788,9 @@ class PairingController extends GetxController with WidgetsBindingObserver {
Future<int> authbindingDevice(BluetoothDevice device) async { Future<int> authbindingDevice(BluetoothDevice device) async {
// 检查设备名称是否包含 DeepSound 或 DeapSound // 检查设备名称是否包含 DeepSound 或 DeapSound
final deviceName = device.name; final deviceName = device.name;
DBProduct? product; // 已移除“按设备名匹配 product”逻辑:设备名可被用户改名,不能作为是否支持的判据。
// 检查是否已有BLE绑定的设备 // 是否支持的设备完全交给下面的 BLE 扫描(按 allproductUuids 过滤)+ 广播内 MAC 比对判定。
// 检查是否已有BLE绑定的设备
if (AppConfig.config.products.isNotEmpty) {
final match = AppConfig.config.products.where(
(d) => d.devicename.contains(deviceName),
);
product = match.isNotEmpty ? match.first : null;
}
final currentBleState = await _bleManager.getConnectionState(); final currentBleState = await _bleManager.getConnectionState();
final names = AppConfig.allproductNames();
final uuids = AppConfig.allproductUuids(); final uuids = AppConfig.allproductUuids();
// 检查是否已有绑定的设备 // 检查是否已有绑定的设备
print("device.address${device.address}"); print("device.address${device.address}");
@ -867,7 +859,9 @@ class PairingController extends GetxController with WidgetsBindingObserver {
} }
print( print(
'获取到 deviceName: $deviceName address: ${device.address} uuids:$uuids'); '获取到 deviceName: $deviceName address: ${device.address} uuids:$uuids');
if (product != null && product.devicetype != 1) { // 无条件做 BLE 扫描验证(不再依赖 product)。扫描按 allproductUuids 过滤,
// 命中后用广播内 MAC 与经典蓝牙地址比对确认,由此判定是否为支持的设备。
{
if (currentBleState == 2) { if (currentBleState == 2) {
//已连接直接返回 //已连接直接返回
return 9; return 9;
@ -989,10 +983,6 @@ class PairingController extends GetxController with WidgetsBindingObserver {
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
} }
_bleManager.stopScan(); _bleManager.stopScan();
// if (product != null && product.devicetype != 1) {
// //ble设备 必须要扫描到结果
// return 0;
// }
} }
return 0; return 0;
//可以跳转1 //可以跳转1

Loading…
Cancel
Save