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;
|
private final SonyHeadphonesProtocol mProtocol;
|
||||||
|
|
||||||
// Track whether we got the first reply
|
// Track whether we got the first init reply
|
||||||
private boolean firstReply = false;
|
|
||||||
private final Handler handler = new Handler();
|
private final Handler handler = new Handler();
|
||||||
private int initRetries = 0;
|
private int initRetries = 0;
|
||||||
|
|
||||||
@@ -53,7 +52,7 @@ public class SonyHeadphonesIoThread extends BtClassicIoThread {
|
|||||||
private final Runnable initSendRunnable = new Runnable() {
|
private final Runnable initSendRunnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
// If we still haven't got any reply, re-send the init
|
// If we still haven't got any reply, re-send the init
|
||||||
if (!firstReply) {
|
if (!mProtocol.hasProtocolImplementation()) {
|
||||||
if (initRetries++ < 2) {
|
if (initRetries++ < 2) {
|
||||||
LOG.warn("Init retry {}", initRetries);
|
LOG.warn("Init retry {}", initRetries);
|
||||||
|
|
||||||
@@ -103,8 +102,6 @@ public class SonyHeadphonesIoThread extends BtClassicIoThread {
|
|||||||
msgStream.write(incoming);
|
msgStream.write(incoming);
|
||||||
} while (incoming[0] != Message.MESSAGE_TRAILER);
|
} while (incoming[0] != Message.MESSAGE_TRAILER);
|
||||||
|
|
||||||
firstReply = true;
|
|
||||||
|
|
||||||
LOG.trace("Raw message: {}", GB.hexdump(msgStream.toByteArray()));
|
LOG.trace("Raw message: {}", GB.hexdump(msgStream.toByteArray()));
|
||||||
|
|
||||||
return msgStream.toByteArray();
|
return msgStream.toByteArray();
|
||||||
|
@@ -104,9 +104,10 @@ public class SonyHeadphonesProtocol extends GBDeviceProtocol {
|
|||||||
} else if (message.getPayload().length == 6) {
|
} else if (message.getPayload().length == 6) {
|
||||||
LOG.warn("Sony Headphones protocol v2 is not yet supported");
|
LOG.warn("Sony Headphones protocol v2 is not yet supported");
|
||||||
return null;
|
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);
|
return requestQueue.remove().encode(sequenceNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasProtocolImplementation() {
|
||||||
|
return protocolImpl != null;
|
||||||
|
}
|
||||||
|
|
||||||
private GBDeviceEvent handleAck() {
|
private GBDeviceEvent handleAck() {
|
||||||
pendingAcks--;
|
pendingAcks--;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user