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

Beacons for Android

Beacons for Android

This presentation is about the beacons devices, the eco-system and how things works and are implemented on Android.

Julien Sanchez

November 24, 2014
Tweet

More Decks by Julien Sanchez

Other Decks in Technology

Transcript

  1. Julien Sanchez @JuSchz Android developer @ Disclamer : Not related

    or have interests on any beacons brand or company
  2. What is a beacon “iBeacon is the trademark for an

    indoor proximity system that Apple Inc. calls “a new class of low-powered, low-cost transmitters that can notify nearby iOS 7 devices of their presence” “ - Wikipedia
  3. What’s in the boooooox ? Bluetooth Low Energy (BLE) using

    “advertising” mode to communicate data - BLE transmitter - Several type of batteries : flat or classic AA, or USB - Can be waterproof - Can embed sensors like temperature or humidity
  4. About Bluetooth and BLE BLE = GAP + GATT +

    HCI + Link Layer + Pairing + AES encryption + Advertising + …... > in Bluetooth Standard (4.0) since 2010, previously known as Wibree source : http://www.bluetooth.com/
  5. BLE on Android Bluetooth Low Energy on Android SDK (

    android.bluetooth.le ) : - introduced on 4.3 (Jelly Bean, July 2013) - more stable on 4.4 (Kitkat, Nov 2013) Android 5.0 (Lollipop, Nov 2014) : - add peripheral mode (can act like a beacon) but devices restricted - batteries consumption improvement Hardware (BLE chips) can be different depending on device maker/brand
  6. the Apple case iBeacon = Apple technology - Patent and

    brand issue - Radius networks “iBeacon Android SDK” : beekn.net/2014/07/ibeacon-for-android Samsung launching beacons ‘rivals’ called Placedge : placedge.samsung.com - Launched mi-november. Still very new. - OS level integration (on TouchWiz ?), apps can be notified by the system when a beacon is detected, even if app not launched (major concern on current integration)
  7. Start scanning // onCreate beaconManager = new BeaconManager(context); String ESTIMOTE_PROXIMITY_UUID

    = "MYB3AC0N-R3GI0N-UUID”; // your beacon region id Region ALL_BEACONS = new Region("MyRegion", ESTIMOTE_PROXIMITY_UUID, null, null); beaconManager.connect(new BeaconManager.ServiceReadyCallback() { @Override public void onServiceReady() { beaconManager.startMonitoring(ALL_BEACONS); // add try/catch } });
  8. Monitoring // Monitoring beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener(){ @Override public void onEnteredRegion(Region region,

    List<Beacon> beacons) { beaconManager.startRanging(region); // add try/catch } @Override public void onExitedRegion(Region region) { beaconManager.stopRanging(region); // add try/catch } });
  9. Ranging // Ranging beaconManager.setRangingListener(new BeaconManager.RangingListener() { @Override public void onBeaconsDiscovered(Region

    region, List<Beacon> beacons) { for (int i = 0; i< beacons.size(); i++) { Beacon b = beacons.get(i); } } });
  10. Background & stop scanning // Batteries consumption beaconManager.setForegroundScanPeriod(2500, 10000); //

    scans for 2s and wait for 10s beaconManager.setBackgroundScanPeriod(5000, 20000); // onStop beaconManager.stopRanging(ALL_BEACONS); // onDestroy beaconManager.disconnect();
  11. Latency // add or update Long timestamp = System.currentTimeMillis(); myBeacons.put(b.getMajor()

    + "-" + b.getMinor(), timestamp); // remove after 10 seconds of unavailability Map.Entry pairs = (Map.Entry) it.next(); if (timestamp - (Long) pairs.getValue()) > 10000){ it.remove(); } Beacons and BleScan can be tricky, add latency :
  12. Bluetooth detection/activation final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // null if

    no bluetooth detected if (!bluetoothAdapter.isEnabled()) { new AlertDialog.Builder(getActivity()) .setMessage(“Do you want to enable bluetooth ?”) .setPositiveButton(“enable”, new DialogInterface.OnClickListener() { bluetoothAdapter.enable(); }).show(); } “Bluetooth should never be enabled without direct user consent.” https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html
  13. BLE Android SDK public void startScan (ScanCallback callback) // from

    android.bluetooth.le => ScanResult{ mDevice=E3:4D:61:0D:DE:08, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=null, mManufacturerSpecificData={76=[2, 21, -35, 62, -126, 119, -53, 115, 66, 127, -117, -124, -2, 31, -122, 38, 98, -73, -34, 8, 97, 13, -68]}, mServiceData={0000180a-0000-1000-8000-00805f9b34fb=[8, -34, 13, 97, 77, -29, -68, 8, -34, 13, 97]}, mTxPowerLevel=-2147483648, mDeviceName=estimote], mRssi=-79, mTimestampNanos=846279071615 } => 0215 DD3E8277CB73427F8B84FE1F862662B7(uuid) DE08(major) 610D(minor) BC [Beacon{macAddress=E3:4D:61:0D:DE:08, proximityUUID=dd3e8277-cb73-427f-8b84-fe1f862662b7, major=56840, minor=24845, measuredPower=-68, rssi=-80}]
  14. Act as a beacon (peripheral mode) Android Lollipop (api 21)

    : Android device can act like a beacon and advertise data. > startAdvertising(AdvertiseSettings settings, AdvertiseData data, AdvertiseCallback callback) AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder(); dataBuilder.addManufacturerData((int) 0, "hi droidCon NL".getBytes()); AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder(); settingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED); settingsBuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH); settingsBuilder.setConnectable(false); // onStartSuccess && onStartFailure methods AdvertiseCallback advertiseCallback = new AdvertiseCallback(){ ... }
  15. Peripheral mode on Nexus “We introduced BLE peripheral mode in

    Android 5.0 Lollipop. Nexus 6 and Nexus 9 are the first two production Nexus devices that support BLE peripheral mode. Due to hardware chipset dependency, older Nexus devices (4/5/7) will not have access to the feature on Lollipop.” Status: WontFix https://code.google.com/p/android-developer-preview/issues/detail?id=1570 Previously avalaible on developer preview : Disable peripheral mode in N5 bug 16545864 Change-Id: I2273716fbce151173c067b8441e749c78e17141e diff --git a/bluetooth/bdroid_buildcfg.h b/bluetooth/bdroid_buildcfg.h -#define BLE_VND_INCLUDED TRUE
  16. Working with beacons Connection / disconnection - need a Faraday

    cage for beacon isolation > Use Microwave oven - Idea by Lionel Tressens ( @ltr ) -
  17. Working with beacons Ranging / Monitoring > put beacons on

    your dog (or cat) - Idea by Doug Thompson (@dusanwriter) - image source : goldenbailey.com
  18. Working with beacons No Beacons ? - Map to locate

    them wikibeacon.org - Apps to emulate beacon on MacBook (need to support BLE) BLE detection app : - nRF master control panel, made byt Nordic Constructor play.google. com/store/apps/details?id=no.nordicsemi.android.mcp
  19. Security on beacon Major problematic/issue : - Advertising mode :

    No cipher and no connection - Spoofing is easy - Beacons configuration : connexion, magnet Ways to improve it : - Check if several beacons having same ids - WIFI / GPS correlation - Estimote introduced “random proximity uuid” - Gimbal mecanism
  20. All Android SDKs - Estimote - Gimbal (sdk differences) -

    Gelo - Bluecats - RadiusNetwork (altbeacon) - Kontakt.io - Sensorberg - Bluesense (to arrive)
  21. Brand SDK inter-operability “Does the SDK support any iBeacon, or

    only Estimote ? ” by Tom Clausing >> com.estimote.sdk.service.BeaconService$InternalLeScanCallback.onLeScan:522 Device XX:XX:XX:XX:XX:XX is not an Estimote beacon
  22. Brand SDK inter-operability import com.estimote.sdk import com.bluecats.sdk; import kontakt.io.sdk; import

    com.gelo.sdk; import com.bluesense.sdk; import com.sensorberg.sdk; ...... Beacons.startEstimote(); Beacons.startBlueCats(); Beacons startKontaktIo(); Beacons startGelo(); Beacons startSensorBerg(); Beacons.startBlueSense(); ......
  23. // com.estimote.sdk.utils.EstimoteBeacons => no instance : difficult to use Java

    Reflection (...) public class EstimoteBeacons { public static boolean isIOSBeacon(Beacon paramBeacon) { (...) } public static boolean isMacBeacon(Beacon paramBeacon) { (...) } public static boolean isOriginalEstimoteUuid(Beacon paramBeacon) { (...) } public static boolean isValidName(String paramString) { (...) } public static boolean isEstimoteBeacon(Beacon paramBeacon) { // return (isMacBeacon(paramBeacon)) || (isIOSBeacon(paramBeacon)) || (isOriginalEstimoteUuid(paramBeacon)) || (isValidName(paramBeacon.getName())); return true; } }
  24. Estimote SDK Compilation and Recreating the jar library : $

    javac -cp "../../../../../estimote-sdk-preview.jar" EstimoteBeacons.java // generate .class file $ jar cfv estimote-universal-sdk.jar *
  25. Alt beacon SDK - Open-source - Powered by Radius Networks

    - Handle all brands using “setBeaconLayout” function github.com/AltBeacon