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

Add requestConnectionPriority #95

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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 <init> ()V
public fun isLoggable (I)Z
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/gatt/CoroutinesGatt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class CoroutinesGatt internal constructor(
override val services: List<BluetoothGattService> get() = bluetoothGatt.services
override fun getService(uuid: UUID): BluetoothGattService? = bluetoothGatt.getService(uuid)

override fun requestConnectionPriority(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we treat them differently internally? Is this a bluetooth concept or just one within our stack?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we treat them differently internally?

What are you referring to when you say "them"?

Is this a bluetooth concept or just one within our stack?

It is a BLE concept. Has to do with how active the radios are for communication. Android sends a request to the remote peripheral to adjust its communication parameters.

priority: Priority
): Boolean = bluetoothGatt.requestConnectionPriority(priority.intValue)

override suspend fun disconnect() {
try {
Able.info { "Disconnecting $this" }
Expand Down Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions core/src/main/java/gatt/GattConnection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ typealias GattConnectionStatus = Int
*/
typealias GattConnectionState = Int

enum class Priority { Low, Balanced, High }

interface GattConnection {

@FlowPreview
val onConnectionStateChange: Flow<OnConnectionStateChange>

fun requestConnectionPriority(priority: Priority): Boolean

suspend fun disconnect(): Unit
}

Expand Down