Android-Scanner-Compat-Library icon indicating copy to clipboard operation
Android-Scanner-Compat-Library copied to clipboard

Addition: filter by service data UUID with mask

Open gregorymarkthomas opened this issue 5 months ago • 2 comments

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

gregorymarkthomas avatar Jan 19 '24 21:01 gregorymarkthomas

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.

CLAassistant avatar Jan 19 '24 21:01 CLAassistant

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

gregorymarkthomas avatar Jan 20 '24 14:01 gregorymarkthomas