ukhsa-collaboration / COVID-19-app-Android-BETA

Source code of the Beta of the NHS COVID-19 Android app
https://covid19.nhs.uk/
MIT License
776 stars 149 forks source link

Backgrounded iOS devices in peripheral mode not detected when running other services #39

Closed micolous closed 4 years ago

micolous commented 4 years ago

Describe the bug

The Android app will not discover iOS devices running the app in the background if they are running any other peripheral service (eg: TraceTogether).

At present, it appears to check for an explicit Apple manufacturer-specific data field value:

https://github.com/nhsx/COVID-19-app-Android-BETA/blob/acfb01e3c40ac8f35cb85b55208e6efa3a10241d/gradle.properties#L29

https://github.com/nhsx/COVID-19-app-Android-BETA/blob/acfb01e3c40ac8f35cb85b55208e6efa3a10241d/app/src/main/java/uk/nhs/nhsx/sonar/android/app/ble/Scanner.kt#L67-L73

The value is: 01 00 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00

Instead, it should check the Apple manufacturer data:

  1. Byte 0 is 0x01 (Overflow area)
  2. Byte 10 bit 0x40 is set
  3. Ignore all other byte/bit values

This could be partially be done with ScanFilter by passing the additional manufacturerDataMask parameter, but you need to ignore the other types of Apple BLE submessages.

To Reproduce

  1. Have another app on the iOS device advertising a peripheral in the background with a different service ID (eg: Singapore's TraceTogether app)
  2. Run the iOS version of the NHSx app with it in peripheral mode
  3. Run the Android version of the NHSx app with it in central mode

Expected behaviour

The Android device in central mode should be able to discover the iOS device in peripheral mode with the app in the background.

Additional context

http://www.davidgyoungtech.com/2020/05/07/hacking-the-overflow-area

This issue wouldn't impact iOS devices finding each other, as CoreBluetooth handles parsing overflow data for apps.

I haven't run a live test of this issue to reproduce it, or test that this would be enough to make it actually work. I also haven't tested how the NHSx app interacts with having TraceTogether on the same device.

But as is, from reading the source code, this definitely doesn't work, regardless of what the other peripheral app does.

micolous commented 4 years ago

Duplicate of https://github.com/nhsx/COVID-19-app-Android-BETA/issues/10