From b5bd4da9b1d1ceefd9238a2d2f27de3973447c76 Mon Sep 17 00:00:00 2001 From: MrYoranimo Date: Mon, 18 Nov 2024 23:17:44 +0100 Subject: [PATCH] Xiaomi SPPv2: Catch exception thrown in onPacketReceived When a received packet causes an exception to be thrown while getting handled in the service's onPacketReceived method, the message will get stuck in the queue because it is never released. Subsequently received messages get lined up after the first message that causes an exception, and since that message is never removed, those newer messages are never processed. Catching the exception thrown from within the onPacketReceived method allows the code flow to continue and therefore remove the troubling message from the queue. --- .../service/devices/xiaomi/XiaomiSppProtocolV2.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiSppProtocolV2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiSppProtocolV2.java index 90e42f29a..a937ab185 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiSppProtocolV2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiSppProtocolV2.java @@ -105,7 +105,11 @@ public class XiaomiSppProtocolV2 extends AbstractXiaomiSppProtocol { break; case PACKET_TYPE_DATA: XiaomiSppPacketV2.DataPacket dataPacket = (XiaomiSppPacketV2.DataPacket) decodedPacket; - support.onPacketReceived(dataPacket.getChannel(), dataPacket.getPayloadBytes(support.getAuthService())); + try { + support.onPacketReceived(dataPacket.getChannel(), dataPacket.getPayloadBytes(support.getAuthService())); + } catch (final Exception ex) { + LOG.error("Exception while handling received packet", ex); + } // TODO: only directly ack protobuf packets, bulk ack others sendAck(decodedPacket.getSequenceNumber()); break;