diff options
author | Alex Blasche <alexander.blasche@qt.io> | 2016-08-04 14:34:59 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2017-01-23 07:15:56 +0000 |
commit | d3ef813db155158c9edbd3eed983da980431b21e (patch) | |
tree | 02ea0b71d26fddb669c2ce22b4be3a92f6d11989 | |
parent | 72f7df5738a8ed168c9d10a0474a5c42999250e8 (diff) |
Protect Android Gatt code behind version checks
Android Bluetooth LE Client support requires API v18 and Server support
requires API v21.
In fact earlier releases of Qt did not actually catch the v18 border
at all. It excisted since Qt 5.5 already.
Change-Id: I9baabf5138b2b0d48f8d09670c4feeef688681fd
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r-- | src/bluetooth/qlowenergycontroller_android.cpp | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp index 9829f28f..0ebe7564 100644 --- a/src/bluetooth/qlowenergycontroller_android.cpp +++ b/src/bluetooth/qlowenergycontroller_android.cpp @@ -60,21 +60,30 @@ QLowEnergyControllerPrivate::~QLowEnergyControllerPrivate() void QLowEnergyControllerPrivate::init() { -} - -void QLowEnergyControllerPrivate::connectToDevice() -{ - // required to pass unit test on default backend - if (remoteDevice.isNull()) { - qWarning() << "Invalid/null remote device address"; - setError(QLowEnergyController::UnknownRemoteDeviceError); - return; - } + // Android Central/Client support starts with v18 + // Peripheral/Server support requires Android API v21 + const bool isPeripheral = (role == QLowEnergyController::PeripheralRole); + const jint version = QtAndroidPrivate::androidSdkVersion(); + + if (isPeripheral) { + if (version < 21) { + qWarning() << "Qt Bluetooth LE Peripheral support not available" + "on Android devices below version 21"; + return; + } - setState(QLowEnergyController::ConnectingState); + hub = new LowEnergyNotificationHub(remoteDevice, isPeripheral, this); + // we only connect to the peripheral role specific signals + // TODO add connections as they get added later on + } else { + if (version < 18) { + qWarning() << "Qt Bluetooth LE Central/Client support not available" + "on Android devices below version 18"; + return; + } - if (!hub) { - hub = new LowEnergyNotificationHub(remoteDevice, false, this); + hub = new LowEnergyNotificationHub(remoteDevice, isPeripheral, this); + // we only connect to the central role specific signals connect(hub, &LowEnergyNotificationHub::connectionUpdated, this, &QLowEnergyControllerPrivate::connectionUpdated); connect(hub, &LowEnergyNotificationHub::servicesDiscovered, @@ -94,6 +103,21 @@ void QLowEnergyControllerPrivate::connectToDevice() connect(hub, &LowEnergyNotificationHub::serviceError, this, &QLowEnergyControllerPrivate::serviceError); } +} + +void QLowEnergyControllerPrivate::connectToDevice() +{ + if (!hub) + return; // Android version below v18 + + // required to pass unit test on default backend + if (remoteDevice.isNull()) { + qWarning() << "Invalid/null remote device address"; + setError(QLowEnergyController::UnknownRemoteDeviceError); + return; + } + + setState(QLowEnergyController::ConnectingState); if (!hub->javaObject().isValid()) { qCWarning(QT_BT_ANDROID) << "Cannot initiate QtBluetoothLE"; |