I am experiencing serious issues with Android 6.0 and some devices with Bluetooth Low Energy. One of those conflictive devices is this one:
DEVICE INFO:
Name: Samsung Galaxy SV
Model number: SM-G900V
Android vers: 6.0.1
Patch level: May 1, 2016
Hard. vers: G900V.05
If I make some stress test based on connecting and disconnecting the app to a BLE peripheral the success ratio barely reaches 50%.
Reading the latest documentation of Android, they recommend to specify the transport mode in the last parameter of connectGatt method to enforce BLE transport connectivity instead of BR/EDR:
device.connectGatt(this, false, mGattCallback, BluetoothDevice.TRANSPORT_LE);
Nothing changed with this improvement.
Following some suggestions and also reading about BLE connectivity issues, I found several related issues with Samsung Galaxy S6 and in one of those they suggested a series of steps to fix BLE connectivity problems. The key one was to clear Bluetooth Share system app data. Doing so, connectivity ratio increased in almost 100% of success immediately. However, if you wait and play with some other BLE apps and connect to other peripherals the problem will be back sooner or later.
There are some apps in Google Play that tries to fix these BLE issues and what they basically do is:
/system/bin/rm -r /data/misc/bluetoothd/*
/system/bin/rm -r /data/misc/hcid/*
Although it is a way to clear bluetooth cache, it requires the device to be rooted which is not a reasonable solution for professional apps.
None of the private Android API's I researched helped me to solve this issue, and the only similar one I found was to enforce service discovery cache cleanup which has nothing to do with the issue.
Using a BLE packet sniffer I see that the ADV_CONNECT_REQ is not even sent from the device to the peripheral, and after a while the Android stack triggers the STATE_DISCONNECTED event in BluetoothGattCallback.
I don't exactly know why this problem occurs in some 6.0 devices and not in others since Bluetooth Share cache seems to be the problem. What is exactly stored there? Just previously connected/paired devices? Am I the only one experiencing this issue? If not, how do you guys tackle it? I would hate to instruct final users on how to Clear Bluetooth Share app Data.
My tests indicate that this is a more general problem with the Android Bluetooth Stack and that the GATT Connection failure rate is about 20 percent, compared with just 2 percent on iOS. You can see my detailed test results here
Part of the problem is the Android BLE link supervision timeout is hard-coded to 20 seconds in Android 4.3-9 (it is 5 seconds as of Android 10 and 750 ms on iOS) so if a connection is lost, most Android devices will fail silently to reconnect for 20 seconds.
But the long link supervision timeout still doesn't explain a high rate of failure on the first connection attempt, or the loss of the connection after a short time.
I have found that different BLE peripherals have much different GATT connection failure rates with the same Android device acting as the central. I have one device on my desk with which my Google Pixel 3a will successfully connect at a rate close to 100 percent, and maintain that connection for hours. I have a two other peripherals where the connection failure rate is closer to 20 percent, and connections cannot ever be held for more than 15 seconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With