Pebble 2: initial hacky reconnect support

Works sometimes, at least less crashes
(#432)
here
Andreas Shimokawa 2016-11-19 23:49:18 +01:00
parent c95587c915
commit 3b250a4568
4 changed files with 14 additions and 4 deletions

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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,

View File

@ -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() {