Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UnderStanding the core of AarogyaSetu App: Blue...

UnderStanding the core of AarogyaSetu App: Bluetooth Low Energy(BLE)

You must have heard about AarogyaSetu - India’s Contact Tracing App, with an objective of identifying hotspots and tracing individuals who have been to these areas or been in contact with someone who has been already infected. This app is built using Bluetooth Low Energy (BLE), which is a low power wireless communication technology that can be used over a short distance to enable smart devices to communicate. This PPT covers the technical implementation of BLE in the app as well as the technical challenges faced during development

Session Link : https://www.youtube.com/watch?v=K4SLf3y6zmE&t=2849s&ab_channel=ADG-Delhi

Niharika Arora

July 11, 2020
Tweet

More Decks by Niharika Arora

Other Decks in Technology

Transcript

  1. Agenda • Origin Story : AarogyaSetu • COVID Tracing •

    Bluetooth Low Energy(BLE) & Advantages over Classic Bluetooth • How BLE advertisement and scanning works? • Technical Challenges & Solutions
  2. Origin Story: AarogyaSetu • Manually tracing the contacts is difficult

    as it is always dependent on a person’s memory.
  3. Origin Story: AarogyaSetu • Manually tracing the contacts is difficult

    as it is always dependent on a person’s memory. • Need of technology intervention.
  4. Origin Story: AarogyaSetu • Manually tracing the contacts is difficult

    as it is always dependent on a person’s memory. • Need of technology intervention. • Aarogya Setu was born with an idea of automatic contact tracing.
  5. COVID TRACING Problem: How can people get to know whether

    they can affected by the person whom they came in close contact with or not?
  6. COVID TRACING Problem: How can people get to know whether

    they can affected by the person whom they came in close contact with? Solution:
  7. Bluetooth v/s GPS • Bluetooth is able to classify close

    contacts with a significantly lower false-positive rate than GPS. • Given that GPS accuracy decreases in indoor environments, entire shopping malls or skyscrapers would be within the margin of error of a single GPS point.
  8. COVID TRACING Problem: How can people get to know whether

    they can affected by the person whom they came in close contact with? Solution: Bluetooth
  9. What is Bluetooth Low Energy (BLE)? A low power wireless

    communication technology that can be used over a short distance to enable smart devices to connect & communicate.
  10. Classic BT v/s BLE Classic Bluetooth Technology BLE Technology Data

    Payload Throughput 2 Mbps ~100 kbps Connection Setup speed Weak Strong Power Consumption High Low Large Scale Network Weak Good
  11. BLE Advertisement • Broadcasting data packets to all nearby devices

    without having to establish a connection. • Have lower power consumption.
  12. BLE Advertisement • Broadcasting data packets to all nearby devices

    without having to establish a connection. • Have lower power consumption. • Strict limit of 31 bytes of advertisement data.
  13. PreRequisites for Advertisement • Bluetooth must be ON. • BluetoothAdapter.isMultipleAdvertisementSupported()

    • Permission: android.Manifest.permission#BLUETOOTH_ADMIN android.Manifest.permission#BLUETOOTH
  14. ADVERTISE_MODE • ADVERTISE_MODE_LOW_POWER * Default and preferred advertising mode. Frequency

    of advertisement will be less. Advertising interval for 1 packet is 1000 ms i.e 1 sec.
  15. ADVERTISE_MODE • ADVERTISE_MODE_LOW_POWER * Default and preferred advertising mode. Frequency

    of advertisement will be less. Advertising interval for 1 packet is 1000 ms i.e 1 sec. • ADVERTISE_MODE_BALANCED * Balanced between advertising frequency and power consumption. Advertising interval for 1 packet is 250 ms.
  16. ADVERTISE_MODE • ADVERTISE_MODE_LOW_POWER * Default and preferred advertising mode. Frequency

    of advertisement will be less. Advertising interval for 1 packet is 1000 ms i.e 1 sec. • ADVERTISE_MODE_BALANCED * Balanced between advertising frequency and power consumption. Advertising interval for 1 packet is 250 ms. • ADVERTISE_MODE_LOW_LATENCY * Makes your device discoverable quickly, but with the highest power consumption,Advertising interval for 1 packet is 100 ms.
  17. AdvertiseSettings a) TX_POWER_LEVEL : transmission (TX) power level Defines the

    visibility range of advertising packets Different Levels: • ADVERTISE_TX_POWER_ULTRA_LOW • ADVERTISE_TX_POWER_LOW • ADVERTISE_TX_POWER_MEDIUM • ADVERTISE_TX_POWER_HIGH
  18. AdvertiseSettings a) TX_POWER_LEVEL : transmission (TX) power level Defines the

    visibility range of advertising packets Different Levels: • ADVERTISE_TX_POWER_ULTRA_LOW • ADVERTISE_TX_POWER_LOW • ADVERTISE_TX_POWER_MEDIUM • ADVERTISE_TX_POWER_HIGH
  19. PreRequisites for Scanning • Bluetooth must be ON. • Permission:

    android.Manifest.permission#ACESS_COARSE_LOCATION (Android 9 or lower) or Permission: android.Manifest.permission#ACESS_FINE_LOCATION • Permission: android.Manifest.permission#BLUETOOTH_ADMIN • Permission: android.Manifest.permission#BLUETOOTH
  20. A Curious Relationship: Android BLE and Location • The Android

    BluetoothLeScanner’s API documentation of startScan(List<ScanFilters>, ScanSettings, ScanCallback) method states: An app must hold ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION. Bluetooth scan can be used to gather information about the location of the user.
  21. BLE Scan val adapter = BluetoothAdapter.getDefaultAdapter() ?: return val bluetoothLeScanner

    = adapter.bluetoothLeScanner bluetoothLeScanner?.startScan(scanFilter, scanSettings,scanCallback)
  22. BLE Scan val adapter = BluetoothAdapter.getDefaultAdapter() ?: return val bluetoothLeScanner

    = adapter.bluetoothLeScanner bluetoothLeScanner?.startScan(scanFilter, scanSettings,scanCallback)
  23. ScanFilter • Service UUIDs • Name • Mac address •

    Service data • Manufacturer specific data
  24. BLE Scan val adapter = BluetoothAdapter.getDefaultAdapter() ?: return val bluetoothLeScanner

    = adapter.bluetoothLeScanner bluetoothLeScanner?.startScan(scanFilter, scanSettings,scanCallback)
  25. ScanSettings PHY : • Lowest(Physical) layer of the Bluetooth low

    energy protocol stack. • Configures the range of radio transmission and reception.
  26. setPhy • PHY_LE_1M • PHY_LE_ALL_SUPPORTED • PHY_LE_2M • PHY_LE_CODED •

    PHY_LE_1M_MASK • PHY_LE_2M_MASK • PHY_LE_CODED_MASK
  27. setPhy • PHY_LE_1M • PHY_LE_ALL_SUPPORTED • PHY_LE_2M • PHY_LE_CODED •

    PHY_LE_1M_MASK • PHY_LE_2M_MASK • PHY_LE_CODED_MASK .
  28. setPhy • PHY_LE_1M • PHY_LE_ALL_SUPPORTED • PHY_LE_2M • PHY_LE_CODED •

    PHY_LE_1M_MASK • PHY_LE_2M_MASK • PHY_LE_CODED_MASK
  29. BLE Scan val adapter = BluetoothAdapter.getDefaultAdapter() ?: return val bluetoothLeScanner

    = adapter.bluetoothLeScanner bluetoothLeScanner?.startScan(scanFilter, scanSettings,scanCallback)
  30. onScanResult() Hold various useful pieces of information: • BluetoothDevice: Name

    and address • RSSI: Received signal strength indication • Timestamp • ScanRecord • Advertisement Flags: Discoverable mode and capabilities of the device like txPowerLevel • Manufacturer Specific Data: Info useful when filtering • Service UUIDs
  31. onScanResult() Hold various useful pieces of information: • BluetoothDevice: Name

    and address • RSSI: Received signal strength indication • Timestamp • ScanRecord • Advertisement Flags: Discoverable mode and capabilities of the device like txPowerLevel • Manufacturer Specific Data: Info useful when filtering • Service UUIDs
  32. RSSI (Received signal strength indication) • Valid range is [-127,

    126] • TXpower is the RSSI value at 1m distance of your beacon.
  33. ScanCallback Methods: • onScanResult(int callbackType, ScanResult result) { .... }

    Returns single scan result at a time • onBatchScanResults (List<ScanResult> results) { …. } Queue up and deliver the scan results after the requested delay
  34. ScanCallback Methods: • onScanResult(int callbackType, ScanResult result) { .... }

    Returns single scan result at a time • onBatchScanResults (List<ScanResult> results) { …. } Queue up and deliver the scan results after the requested delay • onScanFailed(int errorCode) { ….. } Callback when scan could not be started with the error code for cause.
  35. Technical Challenges • Collision Handling & Packets Dropping • iOS

    to iOS & iOS to Android Background Scanning limitations. • Android to iOS Background Scanning limitations • Android 7 BLE Scan TimeOut • Other Bluetooth Vulnerabilities
  36. Collision Handling & Packets Dropping Problem: How to handle collision

    handling and packets dropping when there are large number devices around for scanning as well as advertisement?
  37. Collision Handling & Packets Dropping Problem: How to handle collision

    handling and packets dropping when there are large number devices around for scanning as well as advertisement? Solution: To counter this, We implemented Adaptive scanning.
  38. Adaptive Scanning • Alternative to backoff schemes : • Helped

    us in adjusting the consumption based on the number of close contacts.
  39. Adaptive Scanning • Alternative to backoff schemes : • Helped

    us in adjusting the consumption based on the number of close contacts. • Better scanning performance and covering more people around.
  40. iOS to iOS & iOS to Android Background Scanning limitations.

    Problem: • As per the iOS limitation, iOS is not able to scan if it goes in background due to their framework restrictions.
  41. iOS to iOS & iOS to Android Background Scanning limitations.

    Problem: • As per the iOS limitation, iOS is not able to scan if it goes in background due to their framework restrictions. Solution: GATT server implementation
  42. GATT Example mBluetoothGattServer = mBluetoothManager?.openGattServer(mContext, mGattServerCallback) val service = BluetoothGattService(UUID.fromString(BuildConfig.SERVICE_UUID),

    BluetoothGattService.SERVICE_TYPE_PRIMARY) val uniqueIdChar = BluetoothGattCharacteristic(UUID.fromString(BuildConfig.DID_UUID), BluetoothGattCharacteristic.PROPERTY_READ,BluetoothGattCharacteristic.PERMISSION_READ) uniqueIdChar.setValue(uniqueId) val pingerChar = BluetoothGattCharacteristic(UUID.fromString(BuildConfig.PINGER_UUID), BluetoothGattCharacteristic.PROPERTY_READ,BluetoothGattCharacteristic.PERMISSION_READ) pingerChar.setValue(true.toString())
  43. GATT Example mBluetoothGattServer = mBluetoothManager?.openGattServer(mContext, mGattServerCallback) val service = BluetoothGattService(UUID.fromString(BuildConfig.SERVICE_UUID),

    BluetoothGattService.SERVICE_TYPE_PRIMARY) val uniqueIdChar = BluetoothGattCharacteristic(UUID.fromString(BuildConfig.DID_UUID), BluetoothGattCharacteristic.PROPERTY_READ,BluetoothGattCharacteristic.PERMISSION_READ) uniqueIdChar.setValue(uniqueId) val pingerChar = BluetoothGattCharacteristic(UUID.fromString(BuildConfig.PINGER_UUID), BluetoothGattCharacteristic.PROPERTY_READ,BluetoothGattCharacteristic.PERMISSION_READ) pingerChar.setValue(true.toString()) service.addCharacteristic(uniqueIdChar) service.addCharacteristic(pingerChar)
  44. GATT Example mBluetoothGattServer = mBluetoothManager?.openGattServer(mContext, mGattServerCallback) val service = BluetoothGattService(UUID.fromString(BuildConfig.SERVICE_UUID),

    BluetoothGattService.SERVICE_TYPE_PRIMARY) val uniqueIdChar = BluetoothGattCharacteristic(UUID.fromString(BuildConfig.DID_UUID), BluetoothGattCharacteristic.PROPERTY_READ,BluetoothGattCharacteristic.PERMISSION_READ) uniqueIdChar.setValue(uniqueId) val pingerChar = BluetoothGattCharacteristic(UUID.fromString(BuildConfig.PINGER_UUID), BluetoothGattCharacteristic.PROPERTY_READ,BluetoothGattCharacteristic.PERMISSION_READ) pingerChar.setValue(true.toString()) service.addCharacteristic(uniqueIdChar) service.addCharacteristic(pingerChar) bluetoothGattServer?.addService(service)
  45. Advantage of implementing GATT server • iOS GATT client started

    pinging the device in background for connections. • App remains active and the connection breaks only if the device goes too far.
  46. Android to iOS Background Scanning limitations Problem: iOS app advertises

    in a proprietary advertisement format that is not part of the Bluetooth standard and thus not readable by non-iOS devices.
  47. Android to iOS Background Scanning limitations Problem: iOS app advertises

    in a proprietary advertisement format that is not part of the Bluetooth standard and thus not readable by non-iOS devices. Solution: Implemented reverse search on backend.
  48. Android 7 BLE Scan TimeOut Problem: Android 7.0 introduced a

    BLE scan timeout, where any scan running for 30 minutes or more is effectively stopped automatically and can only resume “opportunistically”
  49. Android 7 BLE Scan TimeOut Problem: Android 7.0 introduced a

    BLE scan timeout, where any scan running for 30 minutes or more is effectively stopped automatically and can only resume “opportunistically” Solution: Starting the scan again after an interval
  50. Bluetooth Vulnerabilities There are vulnerabilities in Bluetooth technology that have

    to be patched at the operating system-level, and we, therefore, urge users to ensure that their operating systems are regularly patched.
  51. Resources Github Link - https://github.com/nic-delhi/AarogyaSetu_Android Medium link - https://medium.com/aarogyasetu/understanding-the-core-of-aarogya-setu-bluetooth-c09de3143fd2 Adaptive

    Scanning Flow Diagram: https://ibb.co/KGgzzFY Download Link - https://play.google.com/store/apps/details?id=nic.goi.aarogyasetu https://apps.apple.com/in/app/aarogyasetu/id1505825357
  52. Contacts • LinkedIn : https://www.linkedin.com/in/niharika-arora-4874967a/ • Medium : https://medium.com/@nik.arora8059 •

    Github : https://github.com/niharika2810 • Twitter : https://twitter.com/Niharik36712833