From e06ecaa7d8c79a043038f89308a3f2b5614094e5 Mon Sep 17 00:00:00 2001 From: Carlos Rafael Giani Date: Sat, 10 Dec 2022 18:49:12 +0100 Subject: [PATCH] comboctl-android: Remove some obsolete / unnecessary / solved TODOs * device is unpaired while discovery is ongoing" does not happen because discovery only occurs if no device is paired. * Using the second offered BluetoothDevice works reliably on all tested phones so far. * AndroidBluetoothDevice throws a BluetoothException if all of its internal connect attempts fail. Signed-off-by: Carlos Rafael Giani --- .../nightscout/comboctl/android/AndroidBluetoothDevice.kt | 5 +++-- .../comboctl/android/AndroidBluetoothInterface.kt | 7 ------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothDevice.kt b/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothDevice.kt index 8f954ec0cb..ae154d22e0 100644 --- a/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothDevice.kt +++ b/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothDevice.kt @@ -67,8 +67,9 @@ class AndroidBluetoothDevice( // just yet (for example because the UI is still shown on the LCD), while // the retryBlocking loop here is in place because the _Android device_ // may not be ready to connect right away. - // TODO: Test and define what happens when all attempts failed. - // The user needs to be informed and given the choice to try again. + // When all attempts fail, retryBlocking() lets the exception pass through. + // That exception is wrapped in BluetoothException, which then needs to be + // handled by the caller. val totalNumAttempts = 5 retryBlocking(numberOfRetries = totalNumAttempts, delayBetweenRetries = 100) { attemptNumber, previousException -> if (abortConnectAttempt) diff --git a/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothInterface.kt b/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothInterface.kt index 3f2ee01dd0..e1dfee66dc 100644 --- a/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothInterface.kt +++ b/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothInterface.kt @@ -381,13 +381,6 @@ class AndroidBluetoothInterface(private val androidContext: Context) : Bluetooth // instance was already processed. This check here instead // verifies if we have seen the same Bluetooth address on // *different* Android Bluetooth device instances. - // TODO: Test how AndroidBluetoothInterface behaves if the - // device is unpaired while discovery is ongoing (manually by - // the user for example). In theory, this should be handled - // properly by the onBondStateChanged function below. - // TODO: This check may not be necessary on all Android - // devices. On some, it seems to also work if we use the - // first offered BluetoothDevice. if (comboctlBtAddress !in previouslyDiscoveredDevices) { previouslyDiscoveredDevices[comboctlBtAddress] = androidBtDevice logger(LogLevel.DEBUG) {