diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6228be672..d9215312c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,7 +19,6 @@ kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-t kotlinx-io = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version = "0.5.4" } tuulbox-collections = { module = "com.juul.tuulbox:collections", version.ref = "tuulbox" } tuulbox-coroutines = { module = "com.juul.tuulbox:coroutines", version.ref = "tuulbox" } -uuid = { module = "com.benasher44:uuid", version = "0.8.4" } wrappers-bom = { module = "org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom", version = "1.0.0-pre.810" } wrappers-web = { module = "org.jetbrains.kotlin-wrappers:kotlin-web" } diff --git a/kable-core/build.gradle.kts b/kable-core/build.gradle.kts index 9df380b50..1ba8c4fa0 100644 --- a/kable-core/build.gradle.kts +++ b/kable-core/build.gradle.kts @@ -25,7 +25,6 @@ kotlin { sourceSets { commonMain.dependencies { api(libs.kotlinx.coroutines.core) - api(libs.uuid) api(project(":kable-exceptions")) implementation(libs.datetime) implementation(libs.tuulbox.collections) diff --git a/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt b/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt index b3897cd80..3aa63d7e6 100644 --- a/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt +++ b/kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt @@ -1,3 +1,5 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable import android.bluetooth.BluetoothAdapter.STATE_OFF @@ -16,7 +18,6 @@ import android.bluetooth.BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE import android.bluetooth.BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE import android.bluetooth.BluetoothGattDescriptor.ENABLE_INDICATION_VALUE import android.bluetooth.BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE -import com.benasher44.uuid.uuidFrom import com.juul.kable.AndroidPeripheral.Priority import com.juul.kable.AndroidPeripheral.Type import com.juul.kable.State.Disconnected @@ -51,8 +52,11 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlin.coroutines.CoroutineContext import kotlin.coroutines.cancellation.CancellationException +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +import kotlin.uuid.toKotlinUuid -private val clientCharacteristicConfigUuid = uuidFrom(CLIENT_CHARACTERISTIC_CONFIG_UUID) +private val clientCharacteristicConfigUuid = Uuid.parse(CLIENT_CHARACTERISTIC_CONFIG_UUID) // Number of service discovery attempts to make if no services are discovered. // https://github.com/JuulLabs/kable/issues/295 @@ -424,7 +428,7 @@ private val Priority.intValue: Int } private val PlatformCharacteristic.configDescriptor: PlatformDescriptor? - get() = descriptors.firstOrNull { clientCharacteristicConfigUuid == it.uuid } + get() = descriptors.firstOrNull { clientCharacteristicConfigUuid == it.uuid.toKotlinUuid() } private val PlatformCharacteristic.supportsNotify: Boolean get() = properties and PROPERTY_NOTIFY != 0 diff --git a/kable-core/src/androidMain/kotlin/BluetoothLeScannerAndroidScanner.kt b/kable-core/src/androidMain/kotlin/BluetoothLeScannerAndroidScanner.kt index 40bf8b603..ab0b761b9 100644 --- a/kable-core/src/androidMain/kotlin/BluetoothLeScannerAndroidScanner.kt +++ b/kable-core/src/androidMain/kotlin/BluetoothLeScannerAndroidScanner.kt @@ -1,3 +1,5 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable import android.bluetooth.le.ScanCallback @@ -23,6 +25,8 @@ import kotlinx.coroutines.channels.trySendBlocking import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.filter +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.toJavaUuid internal class BluetoothLeScannerAndroidScanner( private val filters: List, @@ -142,7 +146,7 @@ private fun FilterPredicate.toNativeScanFilter(): ScanFilter = is Name.Exact -> setDeviceName(filter.exact) is Address -> setDeviceAddress(filter.address) is ManufacturerData -> setManufacturerData(filter.id, filter.data, filter.dataMask) - is Service -> setServiceUuid(ParcelUuid(filter.uuid)) + is Service -> setServiceUuid(ParcelUuid(filter.uuid.toJavaUuid())) else -> throw AssertionError("Unsupported filter element") } } diff --git a/kable-core/src/androidMain/kotlin/Profile.kt b/kable-core/src/androidMain/kotlin/Profile.kt index 975ccb747..bc97217d1 100644 --- a/kable-core/src/androidMain/kotlin/Profile.kt +++ b/kable-core/src/androidMain/kotlin/Profile.kt @@ -1,12 +1,15 @@ @file:JvmName("ProfileAndroid") +@file:OptIn(ExperimentalUuidApi::class) package com.juul.kable import android.bluetooth.BluetoothGattCharacteristic import android.bluetooth.BluetoothGattDescriptor import android.bluetooth.BluetoothGattService -import com.benasher44.uuid.Uuid import com.juul.kable.Characteristic.Properties +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +import kotlin.uuid.toKotlinUuid @Suppress("ACTUAL_WITHOUT_EXPECT") // https://youtrack.jetbrains.com/issue/KT-37316 internal actual typealias PlatformService = BluetoothGattService @@ -24,7 +27,7 @@ public actual data class DiscoveredService internal constructor( public actual val characteristics: List = service.characteristics.map(::DiscoveredCharacteristic) - actual override val serviceUuid: Uuid get() = service.uuid + actual override val serviceUuid: Uuid get() = service.uuid.toKotlinUuid() val instanceId: Int get() = service.instanceId } @@ -35,8 +38,8 @@ public actual data class DiscoveredCharacteristic internal constructor( public actual val descriptors: List = characteristic.descriptors.map(::DiscoveredDescriptor) - actual override val serviceUuid: Uuid get() = characteristic.service.uuid - actual override val characteristicUuid: Uuid get() = characteristic.uuid + actual override val serviceUuid: Uuid get() = characteristic.service.uuid.toKotlinUuid() + actual override val characteristicUuid: Uuid get() = characteristic.uuid.toKotlinUuid() val instanceId: Int get() = characteristic.instanceId public actual val properties: Properties get() = Properties(characteristic.properties) } @@ -45,12 +48,12 @@ public actual data class DiscoveredDescriptor internal constructor( internal actual val descriptor: PlatformDescriptor, ) : Descriptor { - actual override val serviceUuid: Uuid get() = descriptor.characteristic.service.uuid - actual override val characteristicUuid: Uuid get() = descriptor.characteristic.uuid - actual override val descriptorUuid: Uuid get() = descriptor.uuid + actual override val serviceUuid: Uuid get() = descriptor.characteristic.service.uuid.toKotlinUuid() + actual override val characteristicUuid: Uuid get() = descriptor.characteristic.uuid.toKotlinUuid() + actual override val descriptorUuid: Uuid get() = descriptor.uuid.toKotlinUuid() } internal fun PlatformCharacteristic.toLazyCharacteristic() = LazyCharacteristic( - serviceUuid = service.uuid, - characteristicUuid = uuid, + serviceUuid = service.uuid.toKotlinUuid(), + characteristicUuid = uuid.toKotlinUuid(), ) diff --git a/kable-core/src/androidMain/kotlin/ScanResultAndroidAdvertisement.kt b/kable-core/src/androidMain/kotlin/ScanResultAndroidAdvertisement.kt index 3b8469979..3a6b5739a 100644 --- a/kable-core/src/androidMain/kotlin/ScanResultAndroidAdvertisement.kt +++ b/kable-core/src/androidMain/kotlin/ScanResultAndroidAdvertisement.kt @@ -9,10 +9,14 @@ import android.bluetooth.le.ScanResult import android.os.Build.VERSION import android.os.Build.VERSION_CODES import android.os.ParcelUuid -import com.benasher44.uuid.Uuid import com.juul.kable.PlatformAdvertisement.BondState import kotlinx.parcelize.Parcelize +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +import kotlin.uuid.toJavaUuid +import kotlin.uuid.toKotlinUuid +@OptIn(ExperimentalUuidApi::class) @Parcelize internal class ScanResultAndroidAdvertisement( private val scanResult: ScanResult, @@ -65,10 +69,10 @@ internal class ScanResultAndroidAdvertisement( get() = scanResult.scanRecord?.txPowerLevel override val uuids: List - get() = scanResult.scanRecord?.serviceUuids?.map { it.uuid } ?: emptyList() + get() = scanResult.scanRecord?.serviceUuids?.map { it.uuid.toKotlinUuid() } ?: emptyList() override fun serviceData(uuid: Uuid): ByteArray? = - scanResult.scanRecord?.serviceData?.get(ParcelUuid(uuid)) + scanResult.scanRecord?.serviceData?.get(ParcelUuid(uuid.toJavaUuid())) override fun manufacturerData(companyIdentifierCode: Int): ByteArray? = scanResult.scanRecord?.getManufacturerSpecificData(companyIdentifierCode) diff --git a/kable-core/src/androidMain/kotlin/logs/LogMessage.kt b/kable-core/src/androidMain/kotlin/logs/LogMessage.kt index a412244ce..f897d6ccb 100644 --- a/kable-core/src/androidMain/kotlin/logs/LogMessage.kt +++ b/kable-core/src/androidMain/kotlin/logs/LogMessage.kt @@ -1,10 +1,13 @@ @file:JvmName("AndroidLogMessage") +@file:OptIn(ExperimentalUuidApi::class) package com.juul.kable.logs import android.bluetooth.BluetoothGattCharacteristic import android.bluetooth.BluetoothGattDescriptor import com.juul.kable.gatt.GattStatus +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.toKotlinUuid internal actual val LOG_INDENT: String? = null @@ -14,15 +17,15 @@ internal fun LogMessage.detail(status: GattStatus) { internal fun LogMessage.detail(characteristic: BluetoothGattCharacteristic) { detail( - characteristic.service.uuid, - characteristic.uuid, + characteristic.service.uuid.toKotlinUuid(), + characteristic.uuid.toKotlinUuid(), ) } internal fun LogMessage.detail(descriptor: BluetoothGattDescriptor) { detail( - descriptor.characteristic.service.uuid, - descriptor.characteristic.uuid, - descriptor.uuid, + descriptor.characteristic.service.uuid.toKotlinUuid(), + descriptor.characteristic.uuid.toKotlinUuid(), + descriptor.uuid.toKotlinUuid(), ) } diff --git a/kable-core/src/appleMain/kotlin/AdvertisementData.kt b/kable-core/src/appleMain/kotlin/AdvertisementData.kt index d8afc7f79..161a4fb98 100644 --- a/kable-core/src/appleMain/kotlin/AdvertisementData.kt +++ b/kable-core/src/appleMain/kotlin/AdvertisementData.kt @@ -1,12 +1,14 @@ package com.juul.kable -import com.benasher44.uuid.Uuid import platform.CoreBluetooth.CBAdvertisementDataLocalNameKey import platform.CoreBluetooth.CBAdvertisementDataManufacturerDataKey import platform.CoreBluetooth.CBAdvertisementDataServiceUUIDsKey import platform.CoreBluetooth.CBUUID import platform.Foundation.NSData +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) internal value class AdvertisementData(private val source: Map) { val serviceUuids: List? diff --git a/kable-core/src/appleMain/kotlin/CBPeripheralCoreBluetoothAdvertisement.kt b/kable-core/src/appleMain/kotlin/CBPeripheralCoreBluetoothAdvertisement.kt index 42b40f2f3..83be583bd 100644 --- a/kable-core/src/appleMain/kotlin/CBPeripheralCoreBluetoothAdvertisement.kt +++ b/kable-core/src/appleMain/kotlin/CBPeripheralCoreBluetoothAdvertisement.kt @@ -1,6 +1,5 @@ package com.juul.kable -import com.benasher44.uuid.Uuid import platform.CoreBluetooth.CBAdvertisementDataIsConnectable import platform.CoreBluetooth.CBAdvertisementDataLocalNameKey import platform.CoreBluetooth.CBAdvertisementDataManufacturerDataKey @@ -12,7 +11,10 @@ import platform.CoreBluetooth.CBUUID import platform.Foundation.NSData import platform.Foundation.NSNumber import kotlin.experimental.ExperimentalNativeApi +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) internal class CBPeripheralCoreBluetoothAdvertisement( override val rssi: Int, val data: Map, diff --git a/kable-core/src/appleMain/kotlin/CBPeripheralCoreBluetoothPeripheral.kt b/kable-core/src/appleMain/kotlin/CBPeripheralCoreBluetoothPeripheral.kt index 8c22fddb9..1ffa44f56 100644 --- a/kable-core/src/appleMain/kotlin/CBPeripheralCoreBluetoothPeripheral.kt +++ b/kable-core/src/appleMain/kotlin/CBPeripheralCoreBluetoothPeripheral.kt @@ -1,6 +1,5 @@ package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.CentralManagerDelegate.ConnectionEvent import com.juul.kable.CentralManagerDelegate.ConnectionEvent.DidConnect import com.juul.kable.CentralManagerDelegate.ConnectionEvent.DidDisconnect @@ -87,7 +86,10 @@ import platform.Foundation.dataUsingEncoding import platform.darwin.UInt16 import kotlin.coroutines.CoroutineContext import kotlin.coroutines.cancellation.CancellationException +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) internal class CBPeripheralCoreBluetoothPeripheral( parentCoroutineContext: CoroutineContext, internal val cbPeripheral: CBPeripheral, diff --git a/kable-core/src/appleMain/kotlin/CentralManager.kt b/kable-core/src/appleMain/kotlin/CentralManager.kt index 858f6d2c7..93f14806a 100644 --- a/kable-core/src/appleMain/kotlin/CentralManager.kt +++ b/kable-core/src/appleMain/kotlin/CentralManager.kt @@ -1,6 +1,5 @@ package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.logs.Logging import kotlinx.atomicfu.atomic import kotlinx.coroutines.CoroutineScope @@ -14,9 +13,12 @@ import platform.CoreBluetooth.CBPeripheral import platform.CoreBluetooth.CBService import platform.CoreBluetooth.CBUUID import platform.Foundation.NSData +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid private const val DISPATCH_QUEUE_LABEL = "central" +@OptIn(ExperimentalUuidApi::class) public class CentralManager internal constructor( options: Map?, ) { diff --git a/kable-core/src/appleMain/kotlin/CentralManagerCoreBluetoothScanner.kt b/kable-core/src/appleMain/kotlin/CentralManagerCoreBluetoothScanner.kt index 14809a0fa..fe93bd561 100644 --- a/kable-core/src/appleMain/kotlin/CentralManagerCoreBluetoothScanner.kt +++ b/kable-core/src/appleMain/kotlin/CentralManagerCoreBluetoothScanner.kt @@ -1,6 +1,7 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.CentralManagerDelegate.Response.DidDiscoverPeripheral import com.juul.kable.Filter.Service import com.juul.kable.UnmetRequirementReason.BluetoothDisabled @@ -18,6 +19,8 @@ import platform.CoreBluetooth.CBManagerStatePoweredOff import platform.CoreBluetooth.CBManagerStatePoweredOn import platform.CoreBluetooth.CBManagerStateUnauthorized import platform.CoreBluetooth.CBManagerStateUnsupported +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid internal class CentralManagerCoreBluetoothScanner( central: CentralManager, diff --git a/kable-core/src/appleMain/kotlin/Identifier.kt b/kable-core/src/appleMain/kotlin/Identifier.kt index ed5bab470..bb8c3a418 100644 --- a/kable-core/src/appleMain/kotlin/Identifier.kt +++ b/kable-core/src/appleMain/kotlin/Identifier.kt @@ -1,8 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.Uuid -import com.benasher44.uuid.uuidFrom +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid public actual typealias Identifier = Uuid -public actual fun String.toIdentifier(): Identifier = uuidFrom(this) +public actual fun String.toIdentifier(): Identifier = Uuid.parse(this) diff --git a/kable-core/src/appleMain/kotlin/Peripheral.kt b/kable-core/src/appleMain/kotlin/Peripheral.kt index c22bb7a1b..2e57c1a15 100644 --- a/kable-core/src/appleMain/kotlin/Peripheral.kt +++ b/kable-core/src/appleMain/kotlin/Peripheral.kt @@ -2,6 +2,7 @@ package com.juul.kable import kotlinx.coroutines.CoroutineScope import platform.CoreBluetooth.CBPeripheral +import kotlin.uuid.ExperimentalUuidApi public actual fun CoroutineScope.peripheral( advertisement: Advertisement, @@ -11,6 +12,7 @@ public actual fun CoroutineScope.peripheral( return peripheral(advertisement.cbPeripheral, builderAction) } +@OptIn(ExperimentalUuidApi::class) public fun CoroutineScope.peripheral( identifier: Identifier, builderAction: PeripheralBuilderAction = {}, diff --git a/kable-core/src/appleMain/kotlin/PlatformAdvertisement.kt b/kable-core/src/appleMain/kotlin/PlatformAdvertisement.kt index 9780948be..604726780 100644 --- a/kable-core/src/appleMain/kotlin/PlatformAdvertisement.kt +++ b/kable-core/src/appleMain/kotlin/PlatformAdvertisement.kt @@ -1,9 +1,11 @@ package com.juul.kable -import com.benasher44.uuid.Uuid import platform.Foundation.NSData +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid public actual interface PlatformAdvertisement : Advertisement { + @OptIn(ExperimentalUuidApi::class) public fun serviceDataAsNSData(uuid: Uuid): NSData? public val manufacturerDataAsNSData: NSData? public fun manufacturerDataAsNSData(companyIdentifierCode: Int): NSData? diff --git a/kable-core/src/appleMain/kotlin/Profile.kt b/kable-core/src/appleMain/kotlin/Profile.kt index af6d16b8d..f15035d14 100644 --- a/kable-core/src/appleMain/kotlin/Profile.kt +++ b/kable-core/src/appleMain/kotlin/Profile.kt @@ -1,10 +1,13 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.Characteristic.Properties import platform.CoreBluetooth.CBCharacteristic import platform.CoreBluetooth.CBDescriptor import platform.CoreBluetooth.CBService +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid @Suppress("ACTUAL_WITHOUT_EXPECT") // https://youtrack.jetbrains.com/issue/KT-37316 internal actual typealias PlatformService = CBService diff --git a/kable-core/src/appleMain/kotlin/ScannerBuilder.kt b/kable-core/src/appleMain/kotlin/ScannerBuilder.kt index 7ad496251..f8b1ac2fe 100644 --- a/kable-core/src/appleMain/kotlin/ScannerBuilder.kt +++ b/kable-core/src/appleMain/kotlin/ScannerBuilder.kt @@ -1,11 +1,13 @@ package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.logs.Logging import com.juul.kable.logs.LoggingBuilder import platform.CoreBluetooth.CBCentralManagerScanOptionAllowDuplicatesKey import platform.CoreBluetooth.CBCentralManagerScanOptionSolicitedServiceUUIDsKey +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) public actual class ScannerBuilder { @Deprecated( diff --git a/kable-core/src/appleMain/kotlin/Uuid.kt b/kable-core/src/appleMain/kotlin/Uuid.kt index ea0505111..62adeb1ff 100644 --- a/kable-core/src/appleMain/kotlin/Uuid.kt +++ b/kable-core/src/appleMain/kotlin/Uuid.kt @@ -1,15 +1,17 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.Uuid -import com.benasher44.uuid.uuidFrom import platform.CoreBluetooth.CBUUID import platform.Foundation.NSUUID +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid internal fun Uuid.toNSUUID(): NSUUID = NSUUID(toString()) internal fun Uuid.toCBUUID(): CBUUID = CBUUID.UUIDWithString(toString()) internal fun CBUUID.toUuid(): Uuid = when (UUIDString.length) { - 4 -> uuidFrom("0000$UUIDString-0000-1000-8000-00805F9B34FB") - else -> uuidFrom(UUIDString) + 4 -> Uuid.parse("0000$UUIDString-0000-1000-8000-00805F9B34FB") + else -> Uuid.parse(UUIDString) } -internal fun NSUUID.toUuid(): Uuid = uuidFrom(UUIDString) +internal fun NSUUID.toUuid(): Uuid = Uuid.parse(UUIDString) diff --git a/kable-core/src/appleMain/kotlin/logs/LogMessage.kt b/kable-core/src/appleMain/kotlin/logs/LogMessage.kt index ade9b7073..f2f732df3 100644 --- a/kable-core/src/appleMain/kotlin/logs/LogMessage.kt +++ b/kable-core/src/appleMain/kotlin/logs/LogMessage.kt @@ -1,3 +1,5 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable.logs import com.juul.kable.logs.Logging.DataProcessor.Operation @@ -8,6 +10,7 @@ import platform.CoreBluetooth.CBDescriptor import platform.CoreBluetooth.CBService import platform.Foundation.NSData import platform.Foundation.NSError +import kotlin.uuid.ExperimentalUuidApi internal actual val LOG_INDENT: String? = " " diff --git a/kable-core/src/commonMain/kotlin/Advertisement.kt b/kable-core/src/commonMain/kotlin/Advertisement.kt index 929ad48bd..cc0eebc01 100644 --- a/kable-core/src/commonMain/kotlin/Advertisement.kt +++ b/kable-core/src/commonMain/kotlin/Advertisement.kt @@ -1,7 +1,9 @@ package com.juul.kable -import com.benasher44.uuid.Uuid +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) public interface Advertisement { /** diff --git a/kable-core/src/commonMain/kotlin/Bluetooth.kt b/kable-core/src/commonMain/kotlin/Bluetooth.kt index e13946842..904edcebb 100644 --- a/kable-core/src/commonMain/kotlin/Bluetooth.kt +++ b/kable-core/src/commonMain/kotlin/Bluetooth.kt @@ -2,9 +2,10 @@ package com.juul.kable -import com.benasher44.uuid.Uuid import kotlinx.coroutines.flow.Flow import kotlin.jvm.JvmName +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid import com.juul.kable.bluetooth.isSupported as isBluetoothSupported public expect enum class Reason @@ -16,6 +17,7 @@ public object Bluetooth { * * [Bluetooth Core Specification, Vol 3, Part B: 2.5.1 UUID](https://www.bluetooth.com/specifications/specs/?types=adopted&keyword=Core+Specification) */ + @OptIn(ExperimentalUuidApi::class) public object BaseUuid { private const val mostSignificantBits = 4096L // 00000000-0000-1000 @@ -25,7 +27,7 @@ public object Bluetooth { /** @param shortUuid 32-bits (or less) short UUID (if larger than 32-bits, will be truncated to 32-bits). */ public operator fun plus(shortUuid: Long): Uuid = - Uuid(mostSignificantBits + (shortUuid and 0xFFFF_FFFF shl 32), leastSignificantBits) + Uuid.fromLongs(mostSignificantBits + (shortUuid and 0xFFFF_FFFF shl 32), leastSignificantBits) override fun toString(): String = "00000000-0000-1000-8000-00805F9B34FB" } diff --git a/kable-core/src/commonMain/kotlin/Descriptor.kt b/kable-core/src/commonMain/kotlin/Descriptor.kt index 1bc0a05c2..58eabae24 100644 --- a/kable-core/src/commonMain/kotlin/Descriptor.kt +++ b/kable-core/src/commonMain/kotlin/Descriptor.kt @@ -1,6 +1,9 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.Uuid +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid internal fun List.first( descriptorUuid: Uuid, diff --git a/kable-core/src/commonMain/kotlin/Filter.kt b/kable-core/src/commonMain/kotlin/Filter.kt index 34909be45..ff146c57a 100644 --- a/kable-core/src/commonMain/kotlin/Filter.kt +++ b/kable-core/src/commonMain/kotlin/Filter.kt @@ -1,9 +1,12 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.Filter.Name.Exact import com.juul.kable.Filter.Name.Prefix import kotlin.experimental.and +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid /** * All [Filter]s are supported on all platforms, except for [Filter.Address], which is only supported on Android. diff --git a/kable-core/src/commonMain/kotlin/FilterPredicate.kt b/kable-core/src/commonMain/kotlin/FilterPredicate.kt index 9df23b74a..8ca6af6ee 100644 --- a/kable-core/src/commonMain/kotlin/FilterPredicate.kt +++ b/kable-core/src/commonMain/kotlin/FilterPredicate.kt @@ -1,10 +1,13 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.Filter.Address import com.juul.kable.Filter.Name import com.juul.kable.Filter.Service import kotlin.jvm.JvmInline +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid @JvmInline internal value class FilterPredicate( diff --git a/kable-core/src/commonMain/kotlin/FilterPredicateBuilder.kt b/kable-core/src/commonMain/kotlin/FilterPredicateBuilder.kt index 90c8b8bd0..280c8f913 100644 --- a/kable-core/src/commonMain/kotlin/FilterPredicateBuilder.kt +++ b/kable-core/src/commonMain/kotlin/FilterPredicateBuilder.kt @@ -1,7 +1,9 @@ package com.juul.kable -import com.benasher44.uuid.Uuid +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) public class FilterPredicateBuilder internal constructor() { public var name: Filter.Name? = null public var address: String? = null diff --git a/kable-core/src/commonMain/kotlin/ObservationEvent.kt b/kable-core/src/commonMain/kotlin/ObservationEvent.kt index 805db2b87..e93ddc14e 100644 --- a/kable-core/src/commonMain/kotlin/ObservationEvent.kt +++ b/kable-core/src/commonMain/kotlin/ObservationEvent.kt @@ -1,5 +1,7 @@ package com.juul.kable +import kotlin.uuid.ExperimentalUuidApi + internal sealed class ObservationEvent { open val characteristic: Characteristic? get() = null @@ -18,6 +20,7 @@ internal sealed class ObservationEvent { object Disconnected : ObservationEvent() } +@OptIn(ExperimentalUuidApi::class) internal fun ObservationEvent.isAssociatedWith(characteristic: Characteristic): Boolean = when (val eventCharacteristic = this.characteristic) { null -> true // `characteristic` is null for Disconnected, which applies to all characteristics. diff --git a/kable-core/src/commonMain/kotlin/Peripheral.kt b/kable-core/src/commonMain/kotlin/Peripheral.kt index fedffe265..f58340771 100644 --- a/kable-core/src/commonMain/kotlin/Peripheral.kt +++ b/kable-core/src/commonMain/kotlin/Peripheral.kt @@ -3,7 +3,6 @@ package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.WriteType.WithoutResponse import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow diff --git a/kable-core/src/commonMain/kotlin/Profile.kt b/kable-core/src/commonMain/kotlin/Profile.kt index 9fbc67810..91530e475 100644 --- a/kable-core/src/commonMain/kotlin/Profile.kt +++ b/kable-core/src/commonMain/kotlin/Profile.kt @@ -1,13 +1,14 @@ @file:Suppress("ktlint:standard:no-multi-spaces") +@file:OptIn(ExperimentalUuidApi::class) package com.juul.kable -import com.benasher44.uuid.Uuid -import com.benasher44.uuid.uuidFrom import com.juul.kable.Characteristic.Properties import com.juul.kable.WriteType.WithResponse import com.juul.kable.WriteType.WithoutResponse import kotlin.jvm.JvmInline +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid public interface Service { public val serviceUuid: Uuid @@ -122,8 +123,8 @@ public fun characteristicOf( service: String, characteristic: String, ): Characteristic = LazyCharacteristic( - serviceUuid = uuidFrom(service), - characteristicUuid = uuidFrom(characteristic), + serviceUuid = Uuid.parse(service), + characteristicUuid = Uuid.parse(characteristic), ) public fun descriptorOf( @@ -131,9 +132,9 @@ public fun descriptorOf( characteristic: String, descriptor: String, ): Descriptor = LazyDescriptor( - serviceUuid = uuidFrom(service), - characteristicUuid = uuidFrom(characteristic), - descriptorUuid = uuidFrom(descriptor), + serviceUuid = Uuid.parse(service), + characteristicUuid = Uuid.parse(characteristic), + descriptorUuid = Uuid.parse(descriptor), ) internal fun List.obtain( diff --git a/kable-core/src/commonMain/kotlin/logs/Hex.kt b/kable-core/src/commonMain/kotlin/logs/Hex.kt index a3f7682e4..1acbf24b0 100644 --- a/kable-core/src/commonMain/kotlin/logs/Hex.kt +++ b/kable-core/src/commonMain/kotlin/logs/Hex.kt @@ -1,6 +1,7 @@ package com.juul.kable.logs import com.juul.kable.toHexString +import kotlin.uuid.ExperimentalUuidApi public val Hex: Logging.DataProcessor = Hex() @@ -13,6 +14,7 @@ public class HexBuilder internal constructor() { public var lowerCase: Boolean = false } +@OptIn(ExperimentalUuidApi::class) public fun Hex(init: HexBuilder.() -> Unit = {}): Logging.DataProcessor { val config = HexBuilder().apply(init) return Logging.DataProcessor { data, _, _, _, _ -> diff --git a/kable-core/src/commonMain/kotlin/logs/LogMessage.kt b/kable-core/src/commonMain/kotlin/logs/LogMessage.kt index fbf7888e4..1b16b8d4c 100644 --- a/kable-core/src/commonMain/kotlin/logs/LogMessage.kt +++ b/kable-core/src/commonMain/kotlin/logs/LogMessage.kt @@ -1,15 +1,17 @@ package com.juul.kable.logs -import com.benasher44.uuid.Uuid import com.juul.kable.Characteristic import com.juul.kable.Descriptor import com.juul.kable.WriteType import com.juul.kable.logs.Logging.DataProcessor.Operation import com.juul.kable.logs.Logging.Format.Compact import com.juul.kable.logs.Logging.Format.Multiline +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid internal expect val LOG_INDENT: String? +@OptIn(ExperimentalUuidApi::class) internal class LogMessage( private val logging: Logging, platformIdentifier: String?, diff --git a/kable-core/src/commonMain/kotlin/logs/Logging.kt b/kable-core/src/commonMain/kotlin/logs/Logging.kt index ae2a9ac67..691113a38 100644 --- a/kable-core/src/commonMain/kotlin/logs/Logging.kt +++ b/kable-core/src/commonMain/kotlin/logs/Logging.kt @@ -1,7 +1,8 @@ package com.juul.kable.logs -import com.benasher44.uuid.Uuid import com.juul.kable.ObsoleteKableApi +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid public typealias LoggingBuilder = Logging.() -> Unit @@ -48,6 +49,7 @@ public class Logging { public enum class Operation { Read, Write, Change } + @OptIn(ExperimentalUuidApi::class) public fun process( data: ByteArray, operation: Operation?, diff --git a/kable-core/src/commonTest/kotlin/FilterPredicateTests.kt b/kable-core/src/commonTest/kotlin/FilterPredicateTests.kt index df45c3285..cd1b90933 100644 --- a/kable-core/src/commonTest/kotlin/FilterPredicateTests.kt +++ b/kable-core/src/commonTest/kotlin/FilterPredicateTests.kt @@ -1,17 +1,19 @@ package com.juul.kable -import com.benasher44.uuid.uuidFrom import com.juul.kable.Filter.Name.Exact import com.juul.kable.Filter.Name.Prefix import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid import com.juul.kable.Filter.ManufacturerData as ManufacturerDataFilter +@OptIn(ExperimentalUuidApi::class) class FilterPredicateTests { - private val TEST_UUID_1 = uuidFrom("deadbeef-0000-0000-0000-000000000000") - private val TEST_UUID_2 = uuidFrom("0badcafe-0000-0000-0000-000000000000") + private val TEST_UUID_1 = Uuid.parse("deadbeef-0000-0000-0000-000000000000") + private val TEST_UUID_2 = Uuid.parse("0badcafe-0000-0000-0000-000000000000") @Test fun matches_nameFilterVsExactMatch_isTrue() { diff --git a/kable-core/src/commonTest/kotlin/FiltersTests.kt b/kable-core/src/commonTest/kotlin/FiltersTests.kt index 364ea61a9..b82b7449a 100644 --- a/kable-core/src/commonTest/kotlin/FiltersTests.kt +++ b/kable-core/src/commonTest/kotlin/FiltersTests.kt @@ -1,16 +1,18 @@ package com.juul.kable -import com.benasher44.uuid.uuidFrom import com.juul.kable.Filter.Name.Exact import com.juul.kable.Filter.Name.Prefix import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) class FiltersTests { - private val TEST_UUID_1 = uuidFrom("deadbeef-0000-0000-0000-000000000000") - private val TEST_UUID_2 = uuidFrom("0badcafe-0000-0000-0000-000000000000") + private val TEST_UUID_1 = Uuid.parse("deadbeef-0000-0000-0000-000000000000") + private val TEST_UUID_2 = Uuid.parse("0badcafe-0000-0000-0000-000000000000") @Test fun matches_emptySetVsNothing_isTrue() { diff --git a/kable-core/src/commonTest/kotlin/LogMessageTests.kt b/kable-core/src/commonTest/kotlin/LogMessageTests.kt index fd3633fe7..6a046b085 100644 --- a/kable-core/src/commonTest/kotlin/LogMessageTests.kt +++ b/kable-core/src/commonTest/kotlin/LogMessageTests.kt @@ -1,6 +1,7 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.uuidFrom import com.juul.kable.logs.LogMessage import com.juul.kable.logs.Logging import com.juul.kable.logs.Logging.DataProcessor.Operation.Read @@ -9,10 +10,12 @@ import com.juul.kable.logs.Logging.Format.Multiline import com.juul.kable.logs.Logging.Level.Data import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid -private val TEST_UUID_1 = uuidFrom("ad0be000-0000-4000-a000-000000000000") -private val TEST_UUID_2 = uuidFrom("c0c0a000-0000-4000-a000-000000000000") -private val TEST_UUID_3 = uuidFrom("decade00-0000-4000-a000-000000000000") +private val TEST_UUID_1 = Uuid.parse("ad0be000-0000-4000-a000-000000000000") +private val TEST_UUID_2 = Uuid.parse("c0c0a000-0000-4000-a000-000000000000") +private val TEST_UUID_3 = Uuid.parse("decade00-0000-4000-a000-000000000000") class LogMessageTests { diff --git a/kable-core/src/commonTest/kotlin/ObservationTest.kt b/kable-core/src/commonTest/kotlin/ObservationTest.kt index dfa98e2d2..e66f8d9dd 100644 --- a/kable-core/src/commonTest/kotlin/ObservationTest.kt +++ b/kable-core/src/commonTest/kotlin/ObservationTest.kt @@ -1,6 +1,5 @@ package com.juul.kable -import com.benasher44.uuid.uuid4 import com.juul.kable.State.Connected import com.juul.kable.State.Connecting import com.juul.kable.State.Disconnected @@ -19,10 +18,13 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.assertFalse +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) private fun generateCharacteristic() = characteristicOf( - service = uuid4().toString(), - characteristic = uuid4().toString(), + service = Uuid.random().toString(), + characteristic = Uuid.random().toString(), ) @OptIn(ExperimentalCoroutinesApi::class) diff --git a/kable-core/src/jsMain/kotlin/BluetoothAdvertisingEventWebBluetoothAdvertisement.kt b/kable-core/src/jsMain/kotlin/BluetoothAdvertisingEventWebBluetoothAdvertisement.kt index 7b54d801b..cb7a23609 100644 --- a/kable-core/src/jsMain/kotlin/BluetoothAdvertisingEventWebBluetoothAdvertisement.kt +++ b/kable-core/src/jsMain/kotlin/BluetoothAdvertisingEventWebBluetoothAdvertisement.kt @@ -1,11 +1,13 @@ package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.external.BluetoothAdvertisingEvent import com.juul.kable.external.BluetoothDevice import com.juul.kable.external.iterable import org.khronos.webgl.DataView +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) internal class BluetoothAdvertisingEventWebBluetoothAdvertisement( private val advertisement: BluetoothAdvertisingEvent, ) : PlatformAdvertisement { diff --git a/kable-core/src/jsMain/kotlin/BluetoothLEScanOptions.kt b/kable-core/src/jsMain/kotlin/BluetoothLEScanOptions.kt index 935d35178..52a4983dc 100644 --- a/kable-core/src/jsMain/kotlin/BluetoothLEScanOptions.kt +++ b/kable-core/src/jsMain/kotlin/BluetoothLEScanOptions.kt @@ -1,10 +1,11 @@ package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.external.BluetoothLEScanFilterInit import com.juul.kable.external.BluetoothLEScanOptions import com.juul.kable.external.BluetoothManufacturerDataFilterInit import js.objects.jso +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid /** Convert list of public API type to Web Bluetooth (JavaScript) type. */ internal fun List.toBluetoothLEScanOptions(): BluetoothLEScanOptions = jso { @@ -19,6 +20,7 @@ internal fun List.toBluetoothLEScanFilterInit(): Array() diff --git a/kable-core/src/jsMain/kotlin/Options.deprecated.kt b/kable-core/src/jsMain/kotlin/Options.deprecated.kt index e8c493dd3..b55024ba7 100644 --- a/kable-core/src/jsMain/kotlin/Options.deprecated.kt +++ b/kable-core/src/jsMain/kotlin/Options.deprecated.kt @@ -1,7 +1,9 @@ package com.juul.kable -import com.benasher44.uuid.Uuid +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) @Deprecated( message = "Use Options builder instead. See https://github.com/JuulLabs/kable/issues/723 for details.", replaceWith = ReplaceWith("Options { }"), diff --git a/kable-core/src/jsMain/kotlin/Options.kt b/kable-core/src/jsMain/kotlin/Options.kt index 3a0cd454a..46ed0dc94 100644 --- a/kable-core/src/jsMain/kotlin/Options.kt +++ b/kable-core/src/jsMain/kotlin/Options.kt @@ -1,8 +1,11 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.external.RequestDeviceOptions import js.objects.jso +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid /** https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice */ public fun Options(builder: OptionsBuilder.() -> Unit): Options = diff --git a/kable-core/src/jsMain/kotlin/OptionsBuilder.kt b/kable-core/src/jsMain/kotlin/OptionsBuilder.kt index 507f35ef1..43f816ea9 100644 --- a/kable-core/src/jsMain/kotlin/OptionsBuilder.kt +++ b/kable-core/src/jsMain/kotlin/OptionsBuilder.kt @@ -1,7 +1,9 @@ package com.juul.kable -import com.benasher44.uuid.Uuid +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) public class OptionsBuilder internal constructor() { private var filters: List = emptyList() diff --git a/kable-core/src/jsMain/kotlin/PlatformAdvertisement.kt b/kable-core/src/jsMain/kotlin/PlatformAdvertisement.kt index 42e7c37e5..31f78860e 100644 --- a/kable-core/src/jsMain/kotlin/PlatformAdvertisement.kt +++ b/kable-core/src/jsMain/kotlin/PlatformAdvertisement.kt @@ -1,8 +1,10 @@ package com.juul.kable -import com.benasher44.uuid.Uuid import org.khronos.webgl.DataView +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid +@OptIn(ExperimentalUuidApi::class) public actual interface PlatformAdvertisement : Advertisement { public fun serviceDataAsDataView(uuid: Uuid): DataView? public fun manufacturerDataAsDataView(companyIdentifierCode: Int): DataView? diff --git a/kable-core/src/jsMain/kotlin/Profile.kt b/kable-core/src/jsMain/kotlin/Profile.kt index c855fbd55..3b41dcaf8 100644 --- a/kable-core/src/jsMain/kotlin/Profile.kt +++ b/kable-core/src/jsMain/kotlin/Profile.kt @@ -1,6 +1,7 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.Uuid import com.juul.kable.Characteristic.Properties import com.juul.kable.external.BluetoothCharacteristicProperties import com.juul.kable.external.BluetoothRemoteGATTCharacteristic @@ -9,6 +10,8 @@ import com.juul.kable.external.BluetoothRemoteGATTService import com.juul.kable.logs.Logger import com.juul.kable.logs.detail import kotlinx.coroutines.await +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid @Suppress("ACTUAL_WITHOUT_EXPECT") // https://youtrack.jetbrains.com/issue/KT-37316 internal actual typealias PlatformService = BluetoothRemoteGATTService diff --git a/kable-core/src/jsMain/kotlin/Uuid.kt b/kable-core/src/jsMain/kotlin/Uuid.kt index e9aa74568..2b1e63782 100644 --- a/kable-core/src/jsMain/kotlin/Uuid.kt +++ b/kable-core/src/jsMain/kotlin/Uuid.kt @@ -1,9 +1,11 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.Uuid -import com.benasher44.uuid.uuidFrom import com.juul.kable.external.BluetoothServiceUUID import com.juul.kable.external.BluetoothUUID +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid // Number of characters in a 16-bit UUID alias in string hex representation private const val UUID_ALIAS_STRING_LENGTH = 4 @@ -19,7 +21,7 @@ private const val UUID_ALIAS_STRING_LENGTH = 4 internal typealias UUID = String internal fun UUID.toUuid(): Uuid = - uuidFrom( + Uuid.parse( when (length) { UUID_ALIAS_STRING_LENGTH -> BluetoothUUID.canonicalUUID(toInt(16)) else -> this diff --git a/kable-core/src/jvmMain/kotlin/com/juul/kable/Profile.kt b/kable-core/src/jvmMain/kotlin/com/juul/kable/Profile.kt index 42cdb02fb..b6b2a4793 100644 --- a/kable-core/src/jvmMain/kotlin/com/juul/kable/Profile.kt +++ b/kable-core/src/jvmMain/kotlin/com/juul/kable/Profile.kt @@ -1,6 +1,9 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.juul.kable -import com.benasher44.uuid.Uuid +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid internal actual class PlatformService internal actual class PlatformCharacteristic