1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-19 11:30:44 +02:00

reconnect support. Closes #10

This commit is contained in:
Andreas Shimokawa 2015-03-18 12:29:10 +01:00
parent d1ea1b9915
commit a746ed4a2b

View File

@ -289,6 +289,7 @@ public class BluetoothCommunicationService extends Service {
private OutputStream mmOutStream = null;
private boolean mQuit = false;
private boolean mmIsConnected = false;
private int mmConnectionAttempts = 0;
public BtSocketIoThread(String btDeviceAddress) {
mmBtDeviceAddress = btDeviceAddress;
@ -369,10 +370,21 @@ public class BluetoothCommunicationService extends Service {
}
} catch (IOException e) {
if (e.getMessage().contains("socket closed")) { //FIXME: this does not feel right
mBtSocket = null;
setReceiversEnableState(false);
Log.i(TAG, "Bluetooth socket closed, will quit IO Thread");
mQuit = true;
updateNotification("connection lost, trying to reconnect");
while (mmConnectionAttempts++ < 10) {
Log.i(TAG, "Trying to reconnect (attempt " + mmConnectionAttempts + ")");
mmIsConnected = connect(mmBtDeviceAddress);
if (mmIsConnected)
break;
}
mmConnectionAttempts = 0;
if (!mmIsConnected) {
mBtSocket = null;
setReceiversEnableState(false);
Log.i(TAG, "Bluetooth socket closed, will quit IO Thread");
mQuit = true;
}
}
}
}