DFUService

class DFUService(iOSDFUDriver: DFUDriverImplementation?, iOSDFUImageManager: GRPCDFUImageManager?, iOSZipProvider: ZipPackageInterface?, blueLink: BlueLink, proxy: BLEProxy) : BlueLinkEventListener

Exposes performing functionality for Device Firmware Upgrades on supported Last Lock BLE devices Class handles the entire bridge - device DFU process including DFU image fetching and validation, and conducting the firmware upgrade.

Validate and fetch

Assumption: As of internal-libs v1.2, only multi-image DFUs are supported. A .zip file is expected that contains the individual DFU images (application_core and network_core) along with a manifest.json. Failure to include manifest.json will result in the entire process getting aborted.

Note: To avoid deadlocking Last Lock device in DFU mode, enable DFU mode only if the DFU images pass the validation checks

Constructors

Link copied to clipboard
constructor(iOSDFUDriver: DFUDriverImplementation?, iOSDFUImageManager: GRPCDFUImageManager?, iOSZipProvider: ZipPackageInterface?, blueLink: BlueLink, proxy: BLEProxy)

Properties

Link copied to clipboard
Link copied to clipboard
val uiState: StateFlow<DFUUiState>

Functions

Link copied to clipboard
fun cancelDFU()

Cancels any ongoing DFU process

Link copied to clipboard
suspend fun checkForDFU(device: BluetoothDevice, timeoutMs: Long): CheckDFUResult

Checks if a DFU update is available for the given device. Queues a DEVICE_INFORMATION operation to trigger a heartbeat, waits for the firmware version, fetches the DFU image, and compares versions. Updates dfuAvailable, dfuImage, and dfuImageLoading. Runs mutually exclusively.

Link copied to clipboard
suspend fun exitInstallMode(device: BluetoothDevice, exitOOB: ByteArray): Boolean

Exits install mode by sending a reboot command. If device has DFU service available, uses SMP group 1 (reboot). Otherwise, this method falls back to sending SMP reboot for firmware < 2.3.0

Link copied to clipboard

Starts the DFU process for the provided Device. This is called when the device is already in DFU mode. It sets states and allows for DFU to begin.

Link copied to clipboard
Link copied to clipboard
open fun onBLEStateChanged(newState: Boolean)
Link copied to clipboard
open fun onCharacteristicRead(device: BluetoothDevice, characteristic: BluetoothGattCharacteristic, payload: ByteArray, error: Int? = null)

Error if returned will correspond to the BLE GATT error thrown by the device

Link copied to clipboard
open fun onCharacteristicWrite(device: BluetoothDevice, characteristic: BluetoothGattCharacteristic, error: Int? = null, operationType: BlueLinkOperationType)
Link copied to clipboard
open override fun onDeviceConnected(device: BluetoothDevice)
Link copied to clipboard
open fun onDeviceConnectionFailed(device: BluetoothDevice, reason: Int?)
Link copied to clipboard
open override fun onDeviceDisconnected(device: BluetoothDevice, reason: Int?)
Link copied to clipboard
open override fun onDeviceDiscovered(device: BluetoothDevice, advertisementData: BluetoothAdvertisement, rssi: Int, signalStrength: SignalStrength, connectionStatus: BlueLinkDeviceConnectionStatus)
Link copied to clipboard
open override fun onHeartbeat(device: BluetoothDevice, heartbeatData: ByteArray)
Link copied to clipboard
open fun onLocationStateUpdate(newState: Boolean)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun onOperationStart(device: BluetoothDevice, operation: BlueLinkOperation)
Link copied to clipboard
fun reset()

Resets all DFU-related state: flow state, progress, availability, image, and cancels any ongoing DFU.

Link copied to clipboard
suspend fun sendSMPPayload(device: BluetoothDevice, oobPayload: ByteArray): Boolean

Sends an oob command to the device. If device has DFU service available, uses SMP group 64. Otherwise, uses OOB characteristic.

Link copied to clipboard
fun watchUiState(block: (DFUUiState) -> Unit): Closeable