From ae34794cf5d852c30113987ee1727a4f41cfd565 Mon Sep 17 00:00:00 2001 From: Codel1417 <13484789+Codel1417@users.noreply.github.com> Date: Wed, 22 May 2024 22:43:34 -0400 Subject: [PATCH] Add guards against invalid messages --- ios/fastlane/Fastfile | 3 +-- .../Bluetooth/bluetooth_manager_plus.dart | 21 +++++++++++++++---- .../Definitions/Device/device_definition.dart | 12 +++++++---- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/ios/fastlane/Fastfile b/ios/fastlane/Fastfile index 7a533d66..a2277441 100644 --- a/ios/fastlane/Fastfile +++ b/ios/fastlane/Fastfile @@ -27,11 +27,10 @@ platform :ios do archive_path: "../build/ios/archive/Runner.xcarchive", ) upload_to_testflight( - skip_waiting_for_build_processing: true, changelog: changelog, build_number: ENV['BUILD_NUMBER'], app_version: ENV['VERSION'], - #reject_build_waiting_for_review: true, + reject_build_waiting_for_review: true, api_key_path:"APPLE_SECRETS.json" ) end diff --git a/lib/Backend/Bluetooth/bluetooth_manager_plus.dart b/lib/Backend/Bluetooth/bluetooth_manager_plus.dart index e30c126b..07acd1c1 100644 --- a/lib/Backend/Bluetooth/bluetooth_manager_plus.dart +++ b/lib/Backend/Bluetooth/bluetooth_manager_plus.dart @@ -201,11 +201,24 @@ Future initFlutterBluePlus(InitFlutterBluePlusRef ref) async { if (bluetoothCharacteristic.characteristicUuid == Guid("2a19")) { statefulDevice.batteryLevel.value = values.first.toDouble(); } else if (bluetoothCharacteristic.characteristicUuid == Guid("5073792e-4fc0-45a0-b0a5-78b6c1756c91")) { - String value = const Utf8Decoder().convert(values); - statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: value)); - statefulDevice.batteryCharging.value = value == "CHARGE ON"; + try { + String value = const Utf8Decoder().convert(values); + statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: value)); + statefulDevice.batteryCharging.value = value == "CHARGE ON"; + } catch (e, s) { + _bluetoothPlusLogger.warning("Unable to read values: $values", e, s); + statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: "Unknown: ${values.toString()}")); + return; + } } else if (bluetoothCharacteristic.characteristicUuid == Guid(statefulDevice.baseDeviceDefinition.bleRxCharacteristic)) { - String value = const Utf8Decoder().convert(values); + String value = ""; + try { + value = const Utf8Decoder().convert(values); + } catch (e, s) { + _bluetoothPlusLogger.warning("Unable to read values: $values", e, s); + statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: "Unknown: ${values.toString()}")); + return; + } statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: value)); // Firmware Version if (value.startsWith("VER")) { diff --git a/lib/Backend/Definitions/Device/device_definition.dart b/lib/Backend/Definitions/Device/device_definition.dart index 40e5b7c8..73510e6b 100644 --- a/lib/Backend/Definitions/Device/device_definition.dart +++ b/lib/Backend/Definitions/Device/device_definition.dart @@ -110,10 +110,14 @@ class BaseStatefulDevice extends ChangeNotifier { BaseStatefulDevice(this.baseDeviceDefinition, this.baseStoredDevice, this.ref) { commandQueue = CommandQueue(ref, this); - rxCharacteristicStream = FlutterBluePlus.events.onCharacteristicReceived - .asBroadcastStream() - .where((event) => event.device.remoteId.str == baseStoredDevice.btMACAddress && event.characteristic.characteristicUuid.str == baseDeviceDefinition.bleRxCharacteristic) - .map((event) => const Utf8Decoder().convert(event.value)); + rxCharacteristicStream = FlutterBluePlus.events.onCharacteristicReceived.asBroadcastStream().where((event) => event.device.remoteId.str == baseStoredDevice.btMACAddress && event.characteristic.characteristicUuid.str == baseDeviceDefinition.bleRxCharacteristic).map((event) { + try { + return const Utf8Decoder().convert(event.value); + } catch (e, s) { + bluetoothLog.warning("Unable to read values: ${event.value}", e, s); + } + return ""; + }).where((event) => event.isNotEmpty); deviceConnectionState.addListener(() { if (deviceConnectionState.value == ConnectivityState.disconnected) { reset();