mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 19:06:53 +01:00
BtBR/Xiaomi: fix disconnection logic/state handling
This commit is contained in:
parent
75dc546aa9
commit
3ad389d57d
@ -35,8 +35,8 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
@ -162,8 +162,8 @@ public final class BtBRQueue {
|
||||
}
|
||||
}
|
||||
|
||||
LOG.debug("Exited read thread loop, calling disconnect()");
|
||||
disconnect();
|
||||
LOG.debug("Exited read thread loop, disconnecting");
|
||||
GBApplication.deviceService(mGbDevice).disconnect();
|
||||
}
|
||||
};
|
||||
|
||||
@ -232,6 +232,9 @@ public final class BtBRQueue {
|
||||
LOG.error("IO exception while closing socket in disconnect(): ", e);
|
||||
}
|
||||
}
|
||||
|
||||
mBtSocket = null;
|
||||
setDeviceConnectionState(GBDevice.State.NOT_CONNECTED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,8 +114,15 @@ public class XiaomiAuthService extends AbstractXiaomiService {
|
||||
|
||||
// Watch nonce
|
||||
final XiaomiProto.Command command = handleWatchNonce(cmd.getAuth().getWatchNonce());
|
||||
|
||||
if (command == null) {
|
||||
getSupport().disconnect();
|
||||
LOG.error("handleWatchNonce returned null, disconnecting");
|
||||
final GBDevice device = getSupport().getDevice();
|
||||
|
||||
if (device != null) {
|
||||
GBApplication.deviceService(device).disconnect();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -241,11 +241,6 @@ public class XiaomiBleSupport extends XiaomiConnectionSupport {
|
||||
this.commsSupport.setContext(device, adapter, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
this.commsSupport.disconnect();
|
||||
}
|
||||
|
||||
public void sendCommand(final String taskName, final XiaomiProto.Command command) {
|
||||
if (this.characteristicCommandWrite == null) {
|
||||
// Can sometimes happen in race conditions when connecting + receiving calendar event or weather updates
|
||||
|
@ -31,7 +31,6 @@ public abstract class XiaomiConnectionSupport {
|
||||
public abstract void runOnQueue(String taskName, Runnable run);
|
||||
public abstract void dispose();
|
||||
public abstract void setContext(final GBDevice device, final BluetoothAdapter adapter, final Context context);
|
||||
public abstract void disconnect();
|
||||
public abstract void sendCommand(final String taskName, final XiaomiProto.Command command);
|
||||
public abstract void sendDataChunk(final String taskName, final byte[] chunk, @Nullable final XiaomiCharacteristic.SendCallback callback);
|
||||
}
|
||||
|
@ -158,11 +158,6 @@ public class XiaomiSppSupport extends XiaomiConnectionSupport {
|
||||
this.commsSupport.setContext(device, adapter, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
this.commsSupport.disconnect();
|
||||
}
|
||||
|
||||
private int findNextPossiblePreamble(final byte[] haystack) {
|
||||
for (int i = 1; i + 2 < haystack.length; i++) {
|
||||
// check if first byte matches
|
||||
|
@ -171,9 +171,10 @@ public class XiaomiSupport extends AbstractDeviceSupport {
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (getConnectionSpecificSupport() != null) {
|
||||
getConnectionSpecificSupport().dispose();
|
||||
connectionSupport = null;
|
||||
if (this.connectionSupport != null) {
|
||||
XiaomiConnectionSupport connectionSupport = this.connectionSupport;
|
||||
this.connectionSupport = null;
|
||||
connectionSupport.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,12 +203,6 @@ public class XiaomiSupport extends AbstractDeviceSupport {
|
||||
this.cachedFirmwareVersion = version;
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (getConnectionSpecificSupport() != null) {
|
||||
getConnectionSpecificSupport().disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public void handleCommandBytes(final byte[] plainValue) {
|
||||
LOG.debug("Got command: {}", GB.hexdump(plainValue));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user