Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit a28bde0

Browse files
authored
Add requestConnectionPriority (#95)
1 parent cf48141 commit a28bde0

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

core/api/core.api

+10
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public final class com/juul/able/gatt/CoroutinesGatt : com/juul/able/gatt/Gatt {
9090
public fun getServices ()Ljava/util/List;
9191
public fun readCharacteristic (Landroid/bluetooth/BluetoothGattCharacteristic;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
9292
public fun readRemoteRssi (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
93+
public fun requestConnectionPriority (Lcom/juul/able/gatt/Priority;)Z
9394
public fun requestMtu (ILkotlin/coroutines/Continuation;)Ljava/lang/Object;
9495
public fun setCharacteristicNotification (Landroid/bluetooth/BluetoothGattCharacteristic;Z)Z
9596
public fun toString ()Ljava/lang/String;
@@ -107,6 +108,7 @@ public abstract interface class com/juul/able/gatt/Gatt : com/juul/able/gatt/Gat
107108
public abstract interface class com/juul/able/gatt/GattConnection {
108109
public abstract fun disconnect (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
109110
public abstract fun getOnConnectionStateChange ()Lkotlinx/coroutines/flow/Flow;
111+
public abstract fun requestConnectionPriority (Lcom/juul/able/gatt/Priority;)Z
110112
}
111113

112114
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
246248
public final class com/juul/able/gatt/OutOfOrderGattCallbackException : java/lang/IllegalStateException {
247249
}
248250

251+
public final class com/juul/able/gatt/Priority : java/lang/Enum {
252+
public static final field Balanced Lcom/juul/able/gatt/Priority;
253+
public static final field High Lcom/juul/able/gatt/Priority;
254+
public static final field Low Lcom/juul/able/gatt/Priority;
255+
public static fun valueOf (Ljava/lang/String;)Lcom/juul/able/gatt/Priority;
256+
public static fun values ()[Lcom/juul/able/gatt/Priority;
257+
}
258+
249259
public final class com/juul/able/logger/AndroidLogger : com/juul/able/logger/Logger {
250260
public fun <init> ()V
251261
public fun isLoggable (I)Z

core/src/main/java/gatt/CoroutinesGatt.kt

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class CoroutinesGatt internal constructor(
4444
override val services: List<BluetoothGattService> get() = bluetoothGatt.services
4545
override fun getService(uuid: UUID): BluetoothGattService? = bluetoothGatt.getService(uuid)
4646

47+
override fun requestConnectionPriority(
48+
priority: Priority
49+
): Boolean = bluetoothGatt.requestConnectionPriority(priority.intValue)
50+
4751
override suspend fun disconnect() {
4852
try {
4953
Able.info { "Disconnecting $this" }
@@ -157,3 +161,10 @@ class CoroutinesGatt internal constructor(
157161

158162
override fun toString(): String = "CoroutinesGatt(device=${bluetoothGatt.device})"
159163
}
164+
165+
private val Priority.intValue: Int
166+
get() = when (this) {
167+
Priority.Low -> BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER
168+
Priority.Balanced -> BluetoothGatt.CONNECTION_PRIORITY_BALANCED
169+
Priority.High -> BluetoothGatt.CONNECTION_PRIORITY_HIGH
170+
}

core/src/main/java/gatt/GattConnection.kt

+4
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ typealias GattConnectionStatus = Int
3737
*/
3838
typealias GattConnectionState = Int
3939

40+
enum class Priority { Low, Balanced, High }
41+
4042
interface GattConnection {
4143

4244
@FlowPreview
4345
val onConnectionStateChange: Flow<OnConnectionStateChange>
4446

47+
fun requestConnectionPriority(priority: Priority): Boolean
48+
4549
suspend fun disconnect(): Unit
4650
}
4751

0 commit comments

Comments
 (0)