Skip to content

Commit 6f2e213

Browse files
authored
Merge pull request #219 from NordicSemiconductor/bugfix/disconnection
Disconnection issue fixed
2 parents 0fe7809 + 37c4d09 commit 6f2e213

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

client-core-android/src/main/java/no/nordicsemi/kotlin/ble/client/android/Peripheral.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ open class Peripheral(
358358
} catch (_: PeripheralNotConnectedException) {
359359
// Skip service discovery if the peripheral got disconnected.
360360
return
361-
} catch (e: Exception) {
361+
} catch (e: OperationFailedException) {
362362
logger.warn("Failed to request MTU: {}", e.message)
363363
}
364364
}

client-core-android/src/main/java/no/nordicsemi/kotlin/ble/client/android/exception/PeripheralClosedException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ import no.nordicsemi.kotlin.ble.client.android.Peripheral
3838
* Thrown when the peripheral wasn't connected or has been closed.
3939
*
4040
* This exception is thrown from [Peripheral.refreshCache] when the underlying GATT
41-
* object is null..
41+
* object is null.
4242
*/
4343
class PeripheralClosedException: BluetoothException()

client-core/src/main/java/no/nordicsemi/kotlin/ble/client/Peripheral.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ abstract class Peripheral<ID: Any, EX: Peripheral.Executor<ID>>(
534534
}
535535
} finally {
536536
close()
537+
// If before calling disconnect() the state was not Connected (i.e. Connecting),
538+
// the state at this point will be Disconnecting. Change it to Disconnected manually.
539+
_state.compareAndSet(ConnectionState.Disconnecting, ConnectionState.Disconnected())
537540
logger.info("Disconnected from {}", this)
538541
}
539542
}

0 commit comments

Comments
 (0)