android bluetooth stack

18
Nanik Tolaram [email protected] naniktolaram.com ANDROID ANDROID BLUETOOTH BLUETOOTH STACK STACK

Upload: nanik-tolaram

Post on 22-Jan-2018

1.602 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Android Bluetooth Stack

Nanik [email protected]

ANDROID ANDROID BLUETOOTH BLUETOOTH

STACKSTACK

Page 2: Android Bluetooth Stack

topic 2topic 3topic 4

Thank You Thank You !!

Page 3: Android Bluetooth Stack

• Android Platform Engineer@ BlocksGlobal.comAndroid Platform Engineer@ BlocksGlobal.com

• ScreenerOS – ScreenerOS – www.screener.digitalwww.screener.digital & & LumenHealth – www.lumenhealth.coLumenHealth – www.lumenhealth.co

• Android writer for magazine.odroid.comAndroid writer for magazine.odroid.com

• AOSP Contributor - now and then :)AOSP Contributor - now and then :)

About MeAbout Me

Page 4: Android Bluetooth Stack

The StackThe Stack

Page 5: Android Bluetooth Stack

BluetootBluetooth h • Bluetooth Classic vs Bluetooth Low EnergyBluetooth Classic vs Bluetooth Low Energy

• Single Mode vs Dual ModeSingle Mode vs Dual Mode

• Different way of programmingDifferent way of programming

• Android devices are Dual Mode devicesAndroid devices are Dual Mode devices

Page 6: Android Bluetooth Stack

Classic vs Classic vs BLE BLE

Classic BLEStreaming Data (headset, speaker, etc)

Low data transfer

Up to 7 slaves Large no of slaves

Standard profiles (SPP, DUN, PAN)

Profiles based on Generic Attribute Profile (GATT)

Weak connection setup Strong connection setup

Wider coverage Shorter coverage

Power hungry Low power

Page 7: Android Bluetooth Stack

Bluetooth Low Bluetooth Low Energy Energy • Master Slave RoleMaster Slave Role

• Low Latency Connection - 3msLow Latency Connection - 3ms

Page 8: Android Bluetooth Stack

Generic Access ProfileGeneric Access Profile• PRE ConnectionPRE Connection

• Determines connection, advertising and how Determines connection, advertising and how devices interactsdevices interacts

• Define roles – Define roles – PeripheralsPeripherals and and CentralCentral

• DefineDefine payload for Advertising Data and Scan payload for Advertising Data and Scan ResponseResponse

• Advertising ProcessAdvertising Process

Page 9: Android Bluetooth Stack

Generic Attribute Generic Attribute ProfileProfile• POST Connection POST Connection • Define way for data transfer between devicesDefine way for data transfer between devices

Profiles → collection of Services

Services → distinguished by UUID

Characteristics → encapsulates a single data point

Page 10: Android Bluetooth Stack

Bluetooth ProfilesBluetooth Profiles

Source https://www.facebook.com/raytaccorporation/photos/a.557851494377619.1073741829.169782503184522/576294762533292/?type=3

Page 11: Android Bluetooth Stack

Bluetooth Bluetooth StackStack

App1

Android Bluetooth Framework

Bluetooth Stack(Bluedroid / BlueZ)

Linux Kernel + FirmwareLinux Kernel + Firmware

Bluetooth Hardware

App2 App3 App4

Page 12: Android Bluetooth Stack

Bluetooth System Bluetooth System FilesFiles• bluetooth.default.so bluetooth.default.so (external/bluetooth/bluedroid)(external/bluetooth/bluedroid)

• libbluetooth_jni.so (packages/app/Bluetooth/jni)libbluetooth_jni.so (packages/app/Bluetooth/jni)

• libbt-utils.so (external/bluetooth/bluedroid)libbt-utils.so (external/bluetooth/bluedroid)

• libbt-vendor.so (hardware/<vendor>)libbt-vendor.so (hardware/<vendor>)

• libbt-hci.so (external/bluedroid/main) libbt-hci.so (external/bluedroid/main)

Page 13: Android Bluetooth Stack

Switching Switching OnOn

libhardware.solibhardware.so

bluetooth.default.sobluetooth.default.so

Linux KernelLinux Kernel

libbluetooth_jni.solibbluetooth_jni.so

Bluetooth.apkBluetooth.apk

Page 14: Android Bluetooth Stack

Bluez vs Bluez vs BluedroidBluedroid• Community drivenCommunity driven

• Initiate by community vs vendorInitiate by community vs vendor

• Bluez very strong in Linux worldBluez very strong in Linux world

• Bluedroid strong in Android worldBluedroid strong in Android world

Page 15: Android Bluetooth Stack

Classic Classic Programming Programming • Using BluetoothSocketUsing BluetoothSocket

• Pairing process using PINPairing process using PIN

• Blocking call when connectingBlocking call when connecting

• Thread management (important !)Thread management (important !)

• Managed state connection Managed state connection

Page 16: Android Bluetooth Stack

BLE BLE Programming Programming • Android 4.3+ (API 18) Android 4.3+ (API 18)

• Setting Up Bluetooth AdapterSetting Up Bluetooth Adapter

• Scanning for BLE devices Scanning for BLE devices

• Connecting to GATT Connecting to GATT

• Reading AttributesReading Attributes

• Receive NotificationReceive Notification

Page 17: Android Bluetooth Stack

DemDemoo

Page 18: Android Bluetooth Stack

Thank Thank YouYou