mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-10-01 18:59:14 +02:00
reconnect support. Closes #10
This commit is contained in:
parent
d1ea1b9915
commit
a746ed4a2b
@ -289,6 +289,7 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
private OutputStream mmOutStream = null;
|
private OutputStream mmOutStream = null;
|
||||||
private boolean mQuit = false;
|
private boolean mQuit = false;
|
||||||
private boolean mmIsConnected = false;
|
private boolean mmIsConnected = false;
|
||||||
|
private int mmConnectionAttempts = 0;
|
||||||
|
|
||||||
public BtSocketIoThread(String btDeviceAddress) {
|
public BtSocketIoThread(String btDeviceAddress) {
|
||||||
mmBtDeviceAddress = btDeviceAddress;
|
mmBtDeviceAddress = btDeviceAddress;
|
||||||
@ -369,6 +370,16 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (e.getMessage().contains("socket closed")) { //FIXME: this does not feel right
|
if (e.getMessage().contains("socket closed")) { //FIXME: this does not feel right
|
||||||
|
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;
|
mBtSocket = null;
|
||||||
setReceiversEnableState(false);
|
setReceiversEnableState(false);
|
||||||
Log.i(TAG, "Bluetooth socket closed, will quit IO Thread");
|
Log.i(TAG, "Bluetooth socket closed, will quit IO Thread");
|
||||||
@ -376,6 +387,7 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mmIsConnected = false;
|
mmIsConnected = false;
|
||||||
if (mBtSocket != null) {
|
if (mBtSocket != null) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user