1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 02:25:50 +01:00

Pebble: Smarter reconnection attempts

Sleep several seconds between reconnection attempts:
One second after first attempt, two after the second, and so on.

refs #89
This commit is contained in:
Julien Pivotto 2016-04-06 12:37:23 +02:00
parent 51def0d497
commit e42a041448

View File

@ -365,12 +365,19 @@ public class PebbleIoThread extends GBDeviceIoThread {
LOG.info(e.getMessage()); LOG.info(e.getMessage());
mIsConnected = false; mIsConnected = false;
int reconnectAttempts = Integer.valueOf(sharedPrefs.getString("pebble_reconnect_attempts", "10")); int reconnectAttempts = Integer.valueOf(sharedPrefs.getString("pebble_reconnect_attempts", "10"));
int maxReconnectAttempts = reconnectAttempts;
if (reconnectAttempts > 0) { if (reconnectAttempts > 0) {
gbDevice.setState(GBDevice.State.CONNECTING); gbDevice.setState(GBDevice.State.CONNECTING);
gbDevice.sendDeviceUpdateIntent(getContext()); gbDevice.sendDeviceUpdateIntent(getContext());
while (reconnectAttempts-- > 0 && !mQuit && !mIsConnected) { while (reconnectAttempts-- > 0 && !mQuit && !mIsConnected) {
LOG.info("Trying to reconnect (attempts left " + reconnectAttempts + ")"); LOG.info("Trying to reconnect (attempts left " + reconnectAttempts + ")");
mIsConnected = connect(gbDevice.getAddress()); mIsConnected = connect(gbDevice.getAddress());
if (!mIsConnected) {
try {
Thread.sleep((maxReconnectAttempts-reconnectAttempts)*1000);
} catch (InterruptedException ignored) {
}
}
} }
} }
if (!mIsConnected && !mQuit) { if (!mIsConnected && !mQuit) {