diff options
author | Alex Blasche <alexander.blasche@qt.io> | 2016-12-21 17:09:52 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2017-01-23 07:41:24 +0000 |
commit | 072ca4833101f4130e4b4f1122f8e6b3e9ae64bd (patch) | |
tree | 93f07d2fe659765886ed4ed5dbe3cfff010eff92 /src/bluetooth/qlowenergycontroller_android.cpp | |
parent | 145a2e1d0360dc79a7c1fa98ba6a28e9691fd1a6 (diff) |
Android: Add access to BTLE connection parameters
Unfortunately, Android only provides access to a very generic connection
priority. The patch uses the minimalInterval() to determine the desired
priority. Everything below 30ms is high priority and everything above
100ms is low priority. Every other value is balanced priority.
QLowEnergyController::requestConnectionUpdate() was modified
to permit access when the controller is connected, discovered or
in the process of being discovered. The limiting factor is an
existing physical connection.
The documentation was updated to reflect Android's API limitations.
[ChangeLog][QtBluetooth][Android] Added access to BTLE connection
parameter settings.
Task-number: QTBUG-53476
Change-Id: I3e22c65bd9598296a9219463dd05f0d9fc73599d
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_android.cpp')
-rw-r--r-- | src/bluetooth/qlowenergycontroller_android.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp index 20b6519c..6cd1ced1 100644 --- a/src/bluetooth/qlowenergycontroller_android.cpp +++ b/src/bluetooth/qlowenergycontroller_android.cpp @@ -45,6 +45,7 @@ #include <QtBluetooth/QLowEnergyDescriptorData> #include <QtBluetooth/QLowEnergyAdvertisingData> #include <QtBluetooth/QLowEnergyAdvertisingParameters> +#include <QtBluetooth/QLowEnergyConnectionParameters> QT_BEGIN_NAMESPACE @@ -771,8 +772,25 @@ void QLowEnergyControllerPrivate::stopAdvertising() void QLowEnergyControllerPrivate::requestConnectionUpdate(const QLowEnergyConnectionParameters ¶ms) { - Q_UNUSED(params); - qCWarning(QT_BT_ANDROID) << "Connection update not implemented for Android"; + // Possible since Android v21 + // Android does not permit specification of specific latency or min/max + // connection intervals (see BluetoothGatt.requestConnectionPriority() + // In fact, each device manufacturer is permitted to change those values via a config + // file too. Therefore we can only make an approximated guess (see implementation below) + // In addition there is no feedback signal (known bug) from the hardware layer as per v24. + + // TODO recheck in later Android releases whether callback for + // BluetoothGatt.requestConnectionPriority() was added + + if (role != QLowEnergyController::CentralRole) { + qCWarning(QT_BT_ANDROID) << "On Android, connection requests only work for central role"; + return; + } + + bool result = hub->javaObject().callMethod<jboolean>("requestConnectionUpdatePriority", + "(D)Z", params.minimumInterval()); + if (!result) + qCWarning(QT_BT_ANDROID) << "Cannot set connection update priority"; } // Conversion: QBluetoothUuid -> java.util.UUID |