1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-15 21:27:51 +01:00

Sony Headphones: Improve first connection reliability

This commit is contained in:
José Rebelo 2022-01-10 19:03:09 +00:00 committed by Gitea
parent c81a7ab8e4
commit d4840b3c5b
2 changed files with 9 additions and 7 deletions

View File

@ -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();

View File

@ -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--;