Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Characteristic equality for DiscoveredCharacteristic #167

Closed
twyatt opened this issue Oct 7, 2021 · 1 comment · Fixed by #839
Closed

Incorrect Characteristic equality for DiscoveredCharacteristic #167

twyatt opened this issue Oct 7, 2021 · 1 comment · Fixed by #839

Comments

@twyatt
Copy link
Member

twyatt commented Oct 7, 2021

On Android at least (have not checked for the other platforms) the equality check of DiscoveredCharacteristic may be incorrect if the list of descriptors is non-empty:

public data class DiscoveredCharacteristic internal constructor(
override val serviceUuid: Uuid,
override val characteristicUuid: Uuid,
public val descriptors: List<Descriptor>,
) : Characteristic

This is because the equality of a DiscoveredCharacteristic will be checked against it's list of descriptors, and on Android the BluetoothGattDescriptor object does not provide an equals function. So, if we have two descriptor objects in memory that represent the same descriptor on a peripheral, then they will erroneously be seen as not equal.

In most cases this will not be an issue, but the Observers class relies on the correctness of Characteristic equality.

@twyatt
Copy link
Member Author

twyatt commented May 23, 2022

More specifically, the following code should take into account instanceId on Android:

internal fun <T> ObservationEvent<T>.isAssociatedWith(characteristic: Characteristic): Boolean =
this.characteristic.characteristicUuid == characteristic.characteristicUuid &&
this.characteristic.serviceUuid == characteristic.serviceUuid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant