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

Addition: filter by service data UUID with mask #144

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from

Conversation

gregorymarkthomas
Copy link

@gregorymarkthomas gregorymarkthomas commented Jan 19, 2024

Hi NordicSemiconductor + contributors,

Firstly, thankyou for Android-Scanner-Compat-Library! It has really helped me in developing a Bluetooth project that supports Android SDK versions 19 to 34....

This is my first ever attempt at a pull request, so, please let me know if I am missing anything.

Additions to NordicSemiconductor's Android-Scanner-Compat-Library

My fork of the library allows for the filtering of advertising packets by service data, the same as NordicSemiconductor's Android-Scanner-Compat-Library, but also allows for a mask to be set on the service data UUID. This addition is useful if your Android app receives a dynamic service data UUID.

Sample

Use this library fork in the same way as NordicSemiconductor's Android-Scanner-Compat-Library, but, if you want to filter by a masked service data UUID, do so like this:

	ParcelUuid serviceDataUuid = ParcelUuid.fromString("000065y8-5451-2g67-674d-3gds456712g1");
	ParcelUuid serviceDataUuidMask = ParcelUuid.fromString("0000FFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF");
	...
	List<ScanFilter> filters = new ArrayList<>();	
	filters.add(new ScanFilter.Builder().setServiceData(serviceDataUuid, serviceDataUuidMask, null, null).build();
	scanner.startScan(filters, settings, scanCallback);

I have run the tests on Android 14/11/7/5.1.1 devices: all passes (bar BluetoothLeScannerImplOreoTest -> toImpl() on Android 7/5.1.1, as designed I assume).
The gradle version upgrade might be unnecessary - I cannot remember if it was a requirement for Android Studio Hedgehog 2023.1.1 or not.

Let me know if any changes are needed.

Best regards,

Gregory Thomas

…an one file was found with OS independent path 'README.txt'' issue on compilation.
…ceData() filter in ScanFilter class. These were based on the setServiceUuid() tests that also has a uuid mask as an optional input.
…ouches most aspects of this class. Added new setServiceData() implementations which include a mask input for the serviceDataUuid input. I opted to create new functions instead of editing the original ones so that anyone who uses the originals in their code can continue using them as is. As of right now the new tests placed in ScanFilterTest->testsetServiceDataFilter() currently FAIL - I am working on this.
…a can be retrieved for a MASKED service data uuid. This function will throw an exception if more than one UUID is picked up from the list of service UUIDs it checks - this is because we only want to return one set of data. If this occurs, this is either because there is an exact duplicate of an uuid in the list, or that the provided mask is too broad and is picking up more than one uuid. Moved matches..() functions from ScanFilter to a dedicated ScanRecordMatchers class, where all functions have been made static; this is so ScanFilter and ScanRecord can access these functions (ScanRecord, due to the addition of the new getServiceData() function now needs access to

matchesServiceUuid(uuid, mask, uuids)). Some minor reindenting of test code. The changes above allow all existing and new tests pass.
…riginal library has trouble handling masks with all zeros.
…tests to fail and not because a mask of zeros did not work.
…rash if it does not exist. Added some logging to the maskable service data uuid function which grabs data for the given masked uuid, and also turned the IllegalArgumentException into an error log.
Removed original readme info and just added my changes to the library.
Randomised UUID
Updated some tests to use the new way of asserting booleans.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@gregorymarkthomas
Copy link
Author

In my limited testing of hardware filtering, this does require setUseHardwareFilteringIfSupported() to be false, much like setServiceData() without the UUID mask argument.

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 this pull request may close these issues.

None yet

2 participants