Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the max concurrent Ble connections android M+ can have

My app required to connect 9 Ble devices concurrently. In this article and any other resource it write that android 4.4+ can connect only to 7 devices. Is there anything new in M or N versions? Thanks.

like image 551
Maor Hadad Avatar asked Dec 28 '16 15:12

Maor Hadad


2 Answers

The number of connections is limited by the constants MAX_L2CAP_LINKS and GATT_MAX_PHY_CHANNEL which is currently (still) set to 7.

If you try to connect the 8th device with autoConnect = true, the stack will hang and fail to connect again until you restart Bluetooth due to a bug introduced in Android M. If you use autoConnect = false to connect an 8th device you will immediately get an onConnectionStateChange callback with newState = disconnected and no attempt to connect will be made.

I don't know why these constants are so low. Often the hardware itself can do more than 7. For example, Nexus 6P can do 15 if you compile AOSP yourself and change the constants.

Samsung seems to have noticed the issue and increased the constants on some of their devices. For example, Samsung Galaxy Tab A 10.1 can handle 15 BLE connections without modifications.

like image 129
Emil Avatar answered Sep 28 '22 05:09

Emil


It seems that those constants are global limits, and not per app. I am linking to the source of the BT stack in Android. I wonder why those constants are as they are... seem random.

#define GATT_MAX_PHY_CHANNEL 7

https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/master/include/bt_target.h#1428

#define BTA_GATTC_CONN_MAX GATT_MAX_PHY_CHANNEL

https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/master/bta/gatt/bta_gattc_int.h#89

tBTA_GATTC_CONN conn_track[BTA_GATTC_CONN_MAX];

https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/master/bta/gatt/bta_gattc_int.h#424

NOTE

This is the official Android code. Up until Android 7.2 the vendors used to change that implementation a lot. The theory in Android 8 and above is that vendors should not modify it (not enough Android 8 devices on the field to see how this works in practice... at least at time of writing this reply).

like image 32
elcuco Avatar answered Sep 28 '22 04:09

elcuco