Package live.ditto.transports.ble

Types

Link copied to clipboard
data class AddService(val service: BluetoothGattService) : BleServerOperation
Link copied to clipboard
sealed class BleClientOperation

Abstract sealed class representing a type of BLE operation

Link copied to clipboard
sealed class BleServerOperation

Abstract sealed class representing a type of BLE operation

Link copied to clipboard
data class CharacteristicRead(val device: BluetoothDevice, val characteristicUuid: UUID) : BleClientOperation

Read the value of a characteristic represented by characteristicUuid

Link copied to clipboard
data class CharacteristicWrite(    val device: BluetoothDevice,     val characteristicUuid: UUID,     val writeType: Int,     val payload: ByteArray) : BleClientOperation

Write payload as the value of a characteristic represented by characteristicUuid

Link copied to clipboard
class CommandQueue<T>(    handler: Handler,     callbacks: CommandQueueCallback<T>,     operationTimeout: Long) : ConcurrentLinkedQueue<T>
Link copied to clipboard
abstract class CommandQueueCallback<T>
Link copied to clipboard
data class Connect(val device: BluetoothDevice, val context: Context) : BleClientOperation

Connect to device and perform service discovery

Link copied to clipboard
data class ConnectL2CapSocket(val device: BluetoothDevice, val psm: Int) : BleClientOperation
Link copied to clipboard
data class DescriptorRead(val device: BluetoothDevice, val descriptorUuid: UUID) : BleClientOperation

Read the value of a descriptor represented by descriptorUuid

Link copied to clipboard
data class DescriptorWrite(    val device: BluetoothDevice,     val descriptorUuid: UUID,     val payload: ByteArray) : BleClientOperation

Write payload as the value of a descriptor represented by descriptorUuid

Link copied to clipboard
data class DisableNotifications(val device: BluetoothDevice, val characteristicUuid: UUID) : BleClientOperation

Disable notifications/indications on a characteristic represented by characteristicUuid

Link copied to clipboard
data class Disconnect(val device: BluetoothDevice) : BleClientOperation

Disconnect from device and release all connection resources

Link copied to clipboard
data class DisconnectPeripheral(val device: BluetoothDevice) : BleServerOperation

Disconnect from device and release all connection resources

Link copied to clipboard
class DittoBluetoothManager(    val context: Context,     dittoHandleWrapper: DittoHandle,     val config: DittoBluetoothLeConfig)

Owns the BluetoothPlatform and references to the Rust-based BLE Client and Server transports. Previously these were long-lived instances but sometimes the Android BLE stack gums up and stops reporting events properly until the app is restarted. The nuclear solution of dropping and recreating the BluetoothPlatform resolves this situation. At the expense of background support, this manager class will track disabled/enabled/background/foreground events and fully stop or start the platform accordingly.

Link copied to clipboard
data class EnableNotifications(val device: BluetoothDevice, val characteristicUuid: UUID) : BleClientOperation

Enable notifications/indications on a characteristic represented by characteristicUuid

Link copied to clipboard
data class MtuRequest(val device: BluetoothDevice, val mtu: Int) : BleClientOperation

Request for an MTU of mtu

Link copied to clipboard
data class NotifyCharacteristicChanged(    val device: BluetoothDevice,     val characteristic: BluetoothGattCharacteristic,     val confirm: Boolean,     val data: ByteArray) : BleServerOperation
Link copied to clipboard
data class Prefer2MPhy(val device: BluetoothDevice) : BleClientOperation
Link copied to clipboard
data class StartAdvertisingSet(    val adSetParams: AdvertisingSetParameters,     val advertisingData: AdvertiseData,     val scanResponse: AdvertiseData) : BleServerOperation
Link copied to clipboard
data class StartLegacyAdvertising(    val adSettings: AdvertiseSettings,     val advertisingData: AdvertiseData,     val scanResponse: AdvertiseData) : BleServerOperation

Functions

Link copied to clipboard
fun <K, V> ConcurrentHashMap<K, V>.computeIfPresentCompat(key: K & Any, computation: (K, V) -> V?)
Link copied to clipboard
fun BluetoothGattDescriptor.containsPermission(permission: Int): Boolean
Link copied to clipboard
fun BluetoothGattCharacteristic.containsProperty(property: Int): Boolean
Link copied to clipboard
fun BluetoothGatt.findCharacteristic(uuid: UUID): BluetoothGattCharacteristic?
Link copied to clipboard
fun BluetoothGatt.findDescriptor(uuid: UUID): BluetoothGattDescriptor?
Link copied to clipboard
fun BluetoothGattDescriptor.isCccd(): Boolean

Convenience extension function that returns true if this BluetoothGattDescriptor is a Client Characteristic Configuration Descriptor.

Link copied to clipboard
fun BluetoothGattCharacteristic.isIndicatable(): Boolean
Link copied to clipboard
fun BluetoothGattCharacteristic.isNotifiable(): Boolean
Link copied to clipboard
fun BluetoothGattCharacteristic.isReadable(): Boolean
fun BluetoothGattDescriptor.isReadable(): Boolean
Link copied to clipboard
fun BluetoothGattCharacteristic.isWritable(): Boolean
fun BluetoothGattDescriptor.isWritable(): Boolean
Link copied to clipboard
Link copied to clipboard
fun BluetoothGattServer.notifyCharacteristicChangedCompat(    device: BluetoothDevice,     characteristic: BluetoothGattCharacteristic,     confirm: Boolean,     value: ByteArray): Int
Link copied to clipboard
fun BluetoothGattDescriptor.printProperties(): String
Link copied to clipboard
fun <E> ConcurrentLinkedQueue<E>.removeIfCompat(filter: (E) -> Boolean)
Link copied to clipboard
fun String.toAddressBytes(): ByteArray

Android identifies remote devices by MAC address, whereas iOS uses a UUID. The cross-platform code uses 16-byte values to handle full-size UUIDs directly. On Android we expand a MAC address into 16 bytes.

Link copied to clipboard
fun ByteArray.toAddressString(): String

Convert a ByteArray representing a MAC address into that MAC address string.

Link copied to clipboard
fun ByteArray.toUuid(): UUID
fun String.toUuid(): UUID
Link copied to clipboard
fun BluetoothGatt.writeCharacteristicCompat(    characteristic: BluetoothGattCharacteristic,     payload: ByteArray,     writeType: Int): Int
Link copied to clipboard
fun BluetoothGatt.writeDescriptorCompat(descriptor: BluetoothGattDescriptor, payload: ByteArray): Int

Properties

Link copied to clipboard
val CCC_DESCRIPTOR_UUID: UUID

UUID of the Client Characteristic Configuration Descriptor (0x2902).

Link copied to clipboard
val CHAR_UUID_ANNOUNCE: UUID
Link copied to clipboard
val CHAR_UUID_CONTROL_READ: UUID
Link copied to clipboard
val CHAR_UUID_CONTROL_WRITE: UUID
Link copied to clipboard
val CHAR_UUID_PSM: UUID
Link copied to clipboard
val CHAR_UUID_READ: UUID
Link copied to clipboard
val CHAR_UUID_WRITE: UUID
Link copied to clipboard
const val WRITE_DELAY_MS: Long = 5