diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesIoThread.java index 975543a1b..88d8b6bcf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesIoThread.java @@ -41,8 +41,7 @@ public class SonyHeadphonesIoThread extends BtClassicIoThread { private final SonyHeadphonesProtocol mProtocol; - // Track whether we got the first reply - private boolean firstReply = false; + // Track whether we got the first init reply private final Handler handler = new Handler(); private int initRetries = 0; @@ -53,7 +52,7 @@ public class SonyHeadphonesIoThread extends BtClassicIoThread { private final Runnable initSendRunnable = new Runnable() { public void run() { // If we still haven't got any reply, re-send the init - if (!firstReply) { + if (!mProtocol.hasProtocolImplementation()) { if (initRetries++ < 2) { LOG.warn("Init retry {}", initRetries); @@ -103,8 +102,6 @@ public class SonyHeadphonesIoThread extends BtClassicIoThread { msgStream.write(incoming); } while (incoming[0] != Message.MESSAGE_TRAILER); - firstReply = true; - LOG.trace("Raw message: {}", GB.hexdump(msgStream.toByteArray())); return msgStream.toByteArray(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesProtocol.java index 41b6d9a08..8c28ca291 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesProtocol.java @@ -104,9 +104,10 @@ public class SonyHeadphonesProtocol extends GBDeviceProtocol { } else if (message.getPayload().length == 6) { LOG.warn("Sony Headphones protocol v2 is not yet supported"); return null; + } else { + LOG.error("Unexpected init response payload length: {}", message.getPayload().length); + return null; } - - return null; } } @@ -260,6 +261,10 @@ public class SonyHeadphonesProtocol extends GBDeviceProtocol { return requestQueue.remove().encode(sequenceNumber); } + public boolean hasProtocolImplementation() { + return protocolImpl != null; + } + private GBDeviceEvent handleAck() { pendingAcks--;