adolfintel / OpenPods

The Free and Open Source app for monitoring your AirPods on Android
https://fdossena.com/?p=openPods/index.frag
GNU General Public License v3.0
969 stars 164 forks source link

[Question] Why does the Bluetooth LE scan apply a filter with a mask containing "-1"? #104

Closed andrewtran1995 closed 4 years ago

andrewtran1995 commented 4 years ago

Question

I notice that when creating the scan filter for the Bluetooth LE scan to sniff out AirPods, the code sets the manufacturer data mask to -1 for indices 0 and 1. https://github.com/adolfintel/OpenPods/blob/7d8d286350dea24a50674d53ff61d5d85d320651/OpenPods/app/src/main/java/com/dosse/airpods/PodsService.java#L198 I'm a little confused how that works properly, given Android's documentation that the mask should essentially consist of booleans to determine if the mask is applied in that position or not. Would it be possible to get an explanation for how this works? Thanks in advance!

Context

For context, I'm trying to build my own AirPod battery app (giving full credit of the battery information derivation to this repo): andrewtran1995/airpod-battery.

If it is more appropriate to take any of the above offline, please let me know. Thank you for the work you've done thus far, and providing your findings in this open source format! ❤️

adolfintel commented 4 years ago

I don't remember why I used -1 insted of specifying the mask bit by bit, but a value of -1 in binary means that all bits are set to 1.

You are free (and encouraged) to use OpenPods to make other open source apps :)