mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-16 05:37:51 +01:00
Sony Headphones: Improve first connection reliability
This commit is contained in:
parent
c81a7ab8e4
commit
d4840b3c5b
@ -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--;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user