mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-06-05 21:49:48 +02:00
Sony Headphones: Improve first connection reliability
This commit is contained in:
@@ -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();
|
||||
|
@@ -104,11 +104,12 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (protocolImpl == null) {
|
||||
LOG.error("No protocol implementation, ignoring message");
|
||||
@@ -260,6 +261,10 @@ public class SonyHeadphonesProtocol extends GBDeviceProtocol {
|
||||
return requestQueue.remove().encode(sequenceNumber);
|
||||
}
|
||||
|
||||
public boolean hasProtocolImplementation() {
|
||||
return protocolImpl != null;
|
||||
}
|
||||
|
||||
private GBDeviceEvent handleAck() {
|
||||
pendingAcks--;
|
||||
|
||||
|
Reference in New Issue
Block a user