mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 18:15:49 +01:00
Pebble 2: initial hacky reconnect support
Works sometimes, at least less crashes (#432)
This commit is contained in:
parent
c95587c915
commit
3b250a4568
@ -368,8 +368,8 @@ class PebbleIoThread extends GBDeviceIoThread {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (e.getMessage() != null && e.getMessage().contains("socket closed")) { //FIXME: this does not feel right
|
||||
} catch (IOException | ArrayIndexOutOfBoundsException e) {
|
||||
if (e.getMessage() != null && (e instanceof ArrayIndexOutOfBoundsException || e.getMessage().contains("socket closed"))) { //FIXME: this does not feel right
|
||||
LOG.info(e.getMessage());
|
||||
mIsConnected = false;
|
||||
int reconnectAttempts = prefs.getInt("pebble_reconnect_attempts", 10);
|
||||
|
@ -93,7 +93,9 @@ class PebbleGATTClient extends BluetoothGattCallback {
|
||||
if (newState == BluetoothGatt.STATE_CONNECTED) {
|
||||
LOG.info("calling discoverServices()");
|
||||
gatt.discoverServices();
|
||||
|
||||
}
|
||||
else if (newState == BluetoothGatt.STATE_DISCONNECTED){
|
||||
mPebbleLESupport.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,6 +127,9 @@ class PebbleGATTServer extends BluetoothGattServerCallback {
|
||||
|
||||
public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
|
||||
LOG.info("Connection state change for device: " + device.getAddress() + " status = " + status + " newState = " + newState);
|
||||
if (newState == BluetoothGattServer.STATE_DISCONNECTED) {
|
||||
mPebbleLESupport.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void onDescriptorWriteRequest(BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor,
|
||||
|
@ -50,7 +50,7 @@ public class PebbleLESupport {
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
synchronized public void close() {
|
||||
destroyPipedInputReader();
|
||||
if (mPebbleGATTServer != null) {
|
||||
mPebbleGATTServer.close();
|
||||
@ -60,6 +60,11 @@ public class PebbleLESupport {
|
||||
mPebbleGATTClient.close();
|
||||
mPebbleGATTClient = null;
|
||||
}
|
||||
try {
|
||||
mPipedInputStream.close();
|
||||
mPipedOutputStream.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
void createPipedInputReader() {
|
||||
|
Loading…
Reference in New Issue
Block a user