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

Parser priority is required for interoperability #1114

Open
Maximvdw opened this issue Dec 6, 2022 · 4 comments
Open

Parser priority is required for interoperability #1114

Maximvdw opened this issue Dec 6, 2022 · 4 comments

Comments

@Maximvdw
Copy link

Maximvdw commented Dec 6, 2022

AltBeacon is meant to be an 'open' interoperable standard. I have a use case where I have a layout for an alternative beacon that has similarities with AltBeacon but adds additional features. I still want to detect AltBeacon's, but I want to give my parser a priority for trying to find variants on AltBeacon.

To clarify: I have the AltBeacon parser and my own parser. My own parser will detect a subset of beacons detected by the AltBeacon parser

Expected behavior

I originally expected the parser priority to depend on the order on which it was added to the BeaconManager, so I cleared the getBeaconParsers to remove the default AltBeacon parser. I added my own parser and added the AltBeacon parser again.

https://github.com/AltBeacon/android-beacon-library/blob/master/lib/src/main/java/org/altbeacon/beacon/BeaconManager.java#L336-L346

(I would do a .clear() on the list to remove AltBeacon)

Actual behavior

Due to the HashSet

private Set<BeaconParser> mBeaconParsers = new HashSet<>();

the order is not determined
If a beacon is parsed by "a" parser:
for (BeaconParser parser : ScanHelper.this.mBeaconParsers) {
beacon = parser.fromScanData(scanData.scanRecord, scanData.rssi, scanData.device, scanData.timestampMs);
if (beacon != null) {
break;
}
}
other parsers are ignored

I can manage to get the parser working by not 'readding' the AltBeacon parser. However, I still want to detect AltBeacons that are not a subset of my own parser.

Android Beacon Library version

2.19.4
I have tried the beta with the same result.

Possible Fix

Add a priority to the beacon parser or maintain priority based on its order in the beacon manager.

@davidgyoung
Copy link
Member

On first glance, I don't see why the list of BeaconParsers couldn't be maintained in an ArrayList. It seems like that is the simplest solution to give you what you are looking for. If this were the case, you could clear the list of parsers, and re-add them in the desired order.

@Maximvdw
Copy link
Author

Maximvdw commented Dec 7, 2022

yes, an arraylist with the same order as the one from BeaconManager would be perfect

@Maximvdw
Copy link
Author

Is this something that could be implemented in a new release or does this break compatibility with other features?

@davidgyoung
Copy link
Member

I think it is safe to make this change as there is no API contract for the order of evaluation -- right not it is indeterminate based on the implementation of Set inside the JVM, which is also subject to change. I also think it is very unlikely this will affect the vast majority of apps which use common beacon parsers for which there is not any overlap between any two.

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

No branches or pull requests

2 participants