From fe8b7775e2848218a9db3eb32d9b4cfb3506252d Mon Sep 17 00:00:00 2001 From: Travis Wyatt Date: Thu, 3 Dec 2020 22:11:33 -0800 Subject: [PATCH] Add requestConnectionPriority --- core/api/core.api | 10 ++++++++++ core/src/main/java/gatt/CoroutinesGatt.kt | 11 +++++++++++ core/src/main/java/gatt/GattConnection.kt | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/core/api/core.api b/core/api/core.api index 2bd5151..4de5419 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -90,6 +90,7 @@ public final class com/juul/able/gatt/CoroutinesGatt : com/juul/able/gatt/Gatt { public fun getServices ()Ljava/util/List; public fun readCharacteristic (Landroid/bluetooth/BluetoothGattCharacteristic;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun readRemoteRssi (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun requestConnectionPriority (Lcom/juul/able/gatt/Priority;)Z public fun requestMtu (ILkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun setCharacteristicNotification (Landroid/bluetooth/BluetoothGattCharacteristic;Z)Z public fun toString ()Ljava/lang/String; @@ -107,6 +108,7 @@ public abstract interface class com/juul/able/gatt/Gatt : com/juul/able/gatt/Gat public abstract interface class com/juul/able/gatt/GattConnection { public abstract fun disconnect (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun getOnConnectionStateChange ()Lkotlinx/coroutines/flow/Flow; + public abstract fun requestConnectionPriority (Lcom/juul/able/gatt/Priority;)Z } public abstract interface class com/juul/able/gatt/GattIo { @@ -246,6 +248,14 @@ public final class com/juul/able/gatt/OnReadRemoteRssi : com/juul/able/gatt/HasG public final class com/juul/able/gatt/OutOfOrderGattCallbackException : java/lang/IllegalStateException { } +public final class com/juul/able/gatt/Priority : java/lang/Enum { + public static final field Balanced Lcom/juul/able/gatt/Priority; + public static final field High Lcom/juul/able/gatt/Priority; + public static final field Low Lcom/juul/able/gatt/Priority; + public static fun valueOf (Ljava/lang/String;)Lcom/juul/able/gatt/Priority; + public static fun values ()[Lcom/juul/able/gatt/Priority; +} + public final class com/juul/able/logger/AndroidLogger : com/juul/able/logger/Logger { public fun ()V public fun isLoggable (I)Z diff --git a/core/src/main/java/gatt/CoroutinesGatt.kt b/core/src/main/java/gatt/CoroutinesGatt.kt index 5a9e7c0..2c0d0b2 100644 --- a/core/src/main/java/gatt/CoroutinesGatt.kt +++ b/core/src/main/java/gatt/CoroutinesGatt.kt @@ -44,6 +44,10 @@ class CoroutinesGatt internal constructor( override val services: List get() = bluetoothGatt.services override fun getService(uuid: UUID): BluetoothGattService? = bluetoothGatt.getService(uuid) + override fun requestConnectionPriority( + priority: Priority + ): Boolean = bluetoothGatt.requestConnectionPriority(priority.intValue) + override suspend fun disconnect() { try { Able.info { "Disconnecting $this" } @@ -157,3 +161,10 @@ class CoroutinesGatt internal constructor( override fun toString(): String = "CoroutinesGatt(device=${bluetoothGatt.device})" } + +private val Priority.intValue: Int + get() = when (this) { + Priority.Low -> BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER + Priority.Balanced -> BluetoothGatt.CONNECTION_PRIORITY_BALANCED + Priority.High -> BluetoothGatt.CONNECTION_PRIORITY_HIGH + } diff --git a/core/src/main/java/gatt/GattConnection.kt b/core/src/main/java/gatt/GattConnection.kt index faceb53..6f3b40f 100644 --- a/core/src/main/java/gatt/GattConnection.kt +++ b/core/src/main/java/gatt/GattConnection.kt @@ -37,11 +37,15 @@ typealias GattConnectionStatus = Int */ typealias GattConnectionState = Int +enum class Priority { Low, Balanced, High } + interface GattConnection { @FlowPreview val onConnectionStateChange: Flow + fun requestConnectionPriority(priority: Priority): Boolean + suspend fun disconnect(): Unit }