Pebble: change delay between reconects to 1,2,4,8,16,32,64 (max) seconds

here
Andreas Shimokawa 2016-04-06 22:55:04 +02:00
parent 4055cc1173
commit e91b5a07bd
1 changed files with 5 additions and 2 deletions

View File

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