1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-13 08:54:03 +02:00

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

This commit is contained in:
Andreas Shimokawa 2016-04-06 22:55:04 +02:00
parent 4055cc1173
commit e91b5a07bd

View File

@ -365,18 +365,21 @@ 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());
int delaySeconds = 1;
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) { if (!mIsConnected) {
try { try {
Thread.sleep((maxReconnectAttempts-reconnectAttempts)*1000); Thread.sleep(delaySeconds * 1000);
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
} }
if (delaySeconds < 64) {
delaySeconds *= 2;
}
} }
} }
} }