From 1e5b7a9824e902e144dc1e90aa0cf6b5d8bcb775 Mon Sep 17 00:00:00 2001 From: Aleksander Nowakowski Date: Mon, 18 Feb 2019 15:13:00 +0100 Subject: [PATCH] Increase number of reconnection attempts --- .../java/no/nordicsemi/android/dfu/DfuBaseService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java b/dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java index 824cd61..a965964 100644 --- a/dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java +++ b/dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java @@ -1182,8 +1182,9 @@ public abstract class DfuBaseService extends IntentService implements DfuProgres sendLogBroadcast(LOG_LEVEL_ERROR, String.format(Locale.US, "Connection failed (0x%02X): %s", error, GattError.parse(error))); } // Connection usually fails due to a 133 error (device unreachable, or.. something else went wrong). - // Usually trying the same for the second time works. - if (intent.getIntExtra(EXTRA_ATTEMPT, 0) == 0) { + // Usually trying the same for the second time works. Let's try 2 times. + final int attempt = intent.getIntExtra(EXTRA_ATTEMPT, 0); + if (attempt < 2) { sendLogBroadcast(LOG_LEVEL_WARNING, "Retrying..."); if (mConnectionState != STATE_DISCONNECTED) { @@ -1197,7 +1198,7 @@ public abstract class DfuBaseService extends IntentService implements DfuProgres logi("Restarting the service"); final Intent newIntent = new Intent(); newIntent.fillIn(intent, Intent.FILL_IN_COMPONENT | Intent.FILL_IN_PACKAGE); - newIntent.putExtra(EXTRA_ATTEMPT, 1); + newIntent.putExtra(EXTRA_ATTEMPT, attempt + 1); startService(newIntent); return; }