unsupported

protected open suspend fun unsupported(peripheral: Peripheral<*, *>)

Notifies the profile implementation, that the peripheral does not support the required profile services.

This method is called instead of initialize when requiredServiceUuids could not be found on the peripheral, or when they were found but prepare rejected them (by throwing IllegalArgumentException or NoSuchElementException) - both are treated as the profile simply not being supported by this peripheral.

This method runs in the profile's coroutine, same as initialize: it is canceled when the device gets disconnected or the services get invalidated, so calling awaitCancellation() and cleaning up in a finally block works the same way. A profile that records being unsupported can undo that in a finally block, instead of carrying the verdict of one connection into the next:

override suspend fun unsupported(peripheral: Peripheral<*, *>) {
_state.update { State.Unsupported }
try {
awaitCancellation()
} finally {
_state.update { State.Unknown }
}
}

The default implementation does nothing.

Note

This is purely a notification, useful for tracking whether the profile is supported by the connected peripheral (for example, to update application state for an optional profile). It does not affect the connection lifecycle: if the profile was registered as required, the peripheral will still be disconnected with reason RequiredServiceNotFound regardless of what this method does, and without waiting for it to return.

Parameters

peripheral

The peripheral the profile is being resolved on.

See also