From f034981fc3678e832c85461f5a3a26ca0f67413e Mon Sep 17 00:00:00 2001 From: Travis Wyatt Date: Sat, 18 Jan 2025 18:23:20 -0800 Subject: [PATCH] Simplify "client characteristic config" UUID definition --- .../androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt | 3 +-- .../kotlin/bluetooth/ClientCharacteristicConfigUuid.kt | 6 +++--- kable-core/src/androidMain/kotlin/external/Constants.kt | 3 --- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt b/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt index 6f4255721..a0fcf8eec 100644 --- a/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt +++ b/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt @@ -42,7 +42,6 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlin.coroutines.cancellation.CancellationException import kotlin.time.Duration -import kotlin.uuid.toKotlinUuid // Number of service discovery attempts to make if no services are discovered. // https://github.com/JuulLabs/kable/issues/295 @@ -370,7 +369,7 @@ private val Priority.intValue: Int } private val PlatformCharacteristic.configDescriptor: PlatformDescriptor? - get() = descriptors.firstOrNull { clientCharacteristicConfigUuid == it.uuid.toKotlinUuid() } + get() = descriptors.firstOrNull { clientCharacteristicConfigUuid == it.uuid } private val PlatformCharacteristic.supportsNotify: Boolean get() = properties and PROPERTY_NOTIFY != 0 diff --git a/kable-core/src/androidMain/kotlin/bluetooth/ClientCharacteristicConfigUuid.kt b/kable-core/src/androidMain/kotlin/bluetooth/ClientCharacteristicConfigUuid.kt index ba3e47117..d32190256 100644 --- a/kable-core/src/androidMain/kotlin/bluetooth/ClientCharacteristicConfigUuid.kt +++ b/kable-core/src/androidMain/kotlin/bluetooth/ClientCharacteristicConfigUuid.kt @@ -1,6 +1,6 @@ package com.juul.kable.bluetooth -import com.juul.kable.external.CLIENT_CHARACTERISTIC_CONFIG_UUID -import kotlin.uuid.Uuid +import com.juul.kable.Bluetooth +import kotlin.uuid.toJavaUuid -internal val clientCharacteristicConfigUuid = Uuid.parse(CLIENT_CHARACTERISTIC_CONFIG_UUID) +internal val clientCharacteristicConfigUuid = (Bluetooth.BaseUuid + 0x2902).toJavaUuid() diff --git a/kable-core/src/androidMain/kotlin/external/Constants.kt b/kable-core/src/androidMain/kotlin/external/Constants.kt index 1415b6ab6..1213829aa 100644 --- a/kable-core/src/androidMain/kotlin/external/Constants.kt +++ b/kable-core/src/androidMain/kotlin/external/Constants.kt @@ -18,6 +18,3 @@ internal const val GATT_CONN_TERMINATE_LOCAL_HOST = HCI_ERR_CONN_CAUSE_LOCAL_HOS internal const val GATT_CONN_FAIL_ESTABLISH = HCI_ERR_CONN_FAILED_ESTABLISHMENT internal const val GATT_CONN_LMP_TIMEOUT = HCI_ERR_LMP_RESPONSE_TIMEOUT internal const val GATT_CONN_CANCEL = L2CAP_CONN_CANCEL - -// https://android.googlesource.com/platform/development/+/7167a054a8027f75025c865322fa84791a9b3bd1/samples/BluetoothLeGatt/src/com/example/bluetooth/le/SampleGattAttributes.java#27 -internal const val CLIENT_CHARACTERISTIC_CONFIG_UUID = "00002902-0000-1000-8000-00805f9b34fb"