RadioOperationLock

Tracks which RadioOperations are in flight, so the rest of the app can keep out of their way.

Three consumers, which is why one lock replaced the single-purpose FirmwareMaintenanceLock it grew out of: SharedRadioInterfaceService reads suppressesTransport to stay off the device, MeshService reads holders to refuse to stop itself and to hold a wake lock, and the service notification reads it to say what is running.

Holders are tracked as individual leases rather than a set of operation types. The set was wrong: a caller that cancels a job and immediately starts a replacement — which FirmwareUpdateViewModel does, without joining — lets the cancelled job's finally run after the replacement has acquired, and a shared entry would be retired out from under the live holder. Two holders of the same operation are now independent.

Lives in :core:common because the parties sit in modules that cannot see each other: the flows that take an operation are in :feature:firmware and :feature:discovery, and the code that must respect it is in :core:service.

Process-local by design. A process death drops every lease, which is correct — nothing is in flight any more — but it means this narrows the window in which an interrupted flash can strand a device rather than closing it.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The distinct operations currently in flight.

Link copied to clipboard
val holders: StateFlow<Map<Long, RadioOperation>>

Every live lease, keyed by lease id. Emits on every acquire and release.

Link copied to clipboard

True while any operation is in flight.

Link copied to clipboard

True while an operation that needs the transport off the device is in flight.

Functions

Link copied to clipboard

Takes operation and returns the lease that holds it. Each call is a distinct holder.

Link copied to clipboard
fun release(lease: OperationLease?)

Releases lease. Idempotent, and null-safe so a caller can release a hold it may never have taken.

Link copied to clipboard
suspend fun <T> withOperation(operation: RadioOperation, block: suspend () -> T): T

Runs block with operation held, releasing that exact lease even on failure or cancellation.